2014-09-01 40 views
0

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

 - (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; 
} 
+2

你是如何填充您的数据如果一个异步请求时,不要忘记在年底重新加载数据'[的tableView reloadData]' – meda 2014-09-01 22:57:39

回答

1

当您填写了类别数组后,您只需要拨打[self.myTableView reloadData];即可。这将通过调用表视图数据源和委托方法来重新加载用于构造表的所有数据(其中之一是您的- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

此外,请确保您正确设置tableview的委托和数据源属性。

点击此处了解详情: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