Tableview单元格在viewDidLoad方法之前填充

时间:2014-09-01 22:50:41

标签: ios uitableview

我有@property(nonatomic,strong) NSMutableArray *categoriesArray;- (void)viewDidLoad方法中填充了类别。但是我相信- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath会在我的categoriesArray中填充类别之前执行。我在哪里插入代码来填充categoriesArray,以便在为表格单元格方法调用它时填充它?

     - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Category Cell" forIndexPath:indexPath];
    NSDictionary *category = self.categoriesArray[indexPath.row];
    //cell.textLabel.text = [category valueForKey:@"categoryName"];
    return cell;
}

1 个答案:

答案 0 :(得分:1)

您需要在填充类别数组时调用[self.myTableView reloadData];。这将通过调用表视图数据源和委托方法(其中一个是您的- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

重新加载用于构造表的所有数据

另外,请确保正确设置tableview的delegate和dataSource属性。

此处提供更多信息:https://developer.apple.com/library/ios/documentation/uikit/reference/UITableView_Class/Reference/Reference.html#//apple_ref/occ/instm/UITableView/reloadData

https://developer.apple.com/library/ios/documentation/uikit/reference/UITableView_Class/Reference/Reference.html#//apple_ref/occ/instp/UITableView/dataSource

相关问题