2014-09-01 39 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