未调用 UITableView cellforrowatindexpath [英] UITableView cellforrowatindexpath not called

查看:21
本文介绍了未调用 UITableView cellforrowatindexpath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 Iphone 开发还很陌生.所以如果我问一些非常简单的问题,请耐心等待.

I am pretty new to Iphone development . so please bear me if I ask some very simple questions.

在我的应用程序中,我有多个视图(即 .xib 文件).单击主视图(CouponWebsiteViewController.Xib)上的按钮时,应用程序应加载包含 UITable 的第二个视图(BrowseList.Xib),我必须用一些数据填充该 UITable.我编写了以下代码来填充 BrowseList.m 文件中的数据:

In my application I have multiple views(i.e. .xib files). On clicking the button on the main view(CouponWebsiteViewController.Xib) the application should load the second view(BrowseList.Xib) which contains a UITable and I have to populate that UITable with some data. I have written following code to populate the data on BrowseList.m file:

- (void) viewDidLoad{
    arrayData = [[NSArray alloc] init];
    arrayData = [arrayData arrayByAddingObject:@"dfsgdf"];
    arrayData = [arrayData arrayByAddingObject:@"aaaaaa"];
    self.lblNewScreen.text = [arrayData objectAtIndex:0];
    [super viewDidLoad];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [arrayData count];
}

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView 
         cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] 
                 initWithStyle:UITableViewCellStyleDefault 
                 reuseIdentifier:CellIdentifier] 
                autorelease];
    }

    NSString *cellValue = [arrayData objectAtIndex:indexPath.row];
    cell.textLabel.text = cellValue;
    [tableView setEditing:YES animated:YES];
    return cell;
}

但是它没有填充表中的数据,当我调试这段代码时,我发现它没有执行 cellForRowAtIndexPath 方法,而是在调试 numberOfRowsInSection 和 numberOfSectionsInTableView 方法.

But It is not populating the data in table , when I debug this code I found that it is not executing cellForRowAtIndexPath method but it is debugging numberOfRowsInSection and numberOfSectionsInTableView methods.

但有趣的是,当我在 CouponWebsiteViewController.m 上(即在主视图上)编写相同的代码时,它会填充表中的数据.

But the interesting thing is when I write the same code on the CouponWebsiteViewController.m (i.e. on main view) then it is populating the data in table.

关键是这段代码在主视图上运行良好,但不适用于其他视图.

The point is this code is working fine on the main view but it does not work for the other views.

任何人都可以告诉我我缺少什么或任何其他方式在主视图以外的视图上填充 UITable.

Can any one tell me what am I missing or any other way to populate the UITable on views other than the main view.

提前致谢.高拉夫

推荐答案

我并不积极,但这里有一些想法.

I'm not positive but here are some ideas.

  • 我认为当您将数组代码放入 viewDidLoad 时,为时已晚.ViewDidLoad 在数据已经放入表格后执行.尝试将此代码放入 initWithStyle 方法或您拥有的任何 init 方法中.或者您甚至可以将其放入 ViewWillAppear 方法中,但请务必遵循下一个建议.
  • 您可以尝试的另一件事是,只需在 viewDidLoad 方法的末尾调用 [self.tableView reloadData].虽然这不像第一个建议那么理想.
  • I think when you put that array code in viewDidLoad it's too late. ViewDidLoad is executed after the data has already been placed in the table. Try putting this code in the initWithStyle method or whatever init method you have. Or you could even put it int the ViewWillAppear method, but then make sure to follow this next suggestion.
  • The other thing you could try is, just call [self.tableView reloadData] at the end of the viewDidLoad method. Although that's not as ideal as the first suggestion.

这篇关于未调用 UITableView cellforrowatindexpath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆