2016-02-12 16 views
3
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSString *CellIdentifier = @"cell"; 
    CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (cell == nil) 
    { 
     cell = [[CustomCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
     [cell addButtons:buttonsArray]; 
    } 

    [cell renderCell:[self.dataArray objectAtIndex:indexPath.row]]; 
    return cell; 
} 

viewDidAppear buttonArray改變,所以我想更新我的細胞新buttonArray。我使用[tableView reloadData](cell != nil)我不能更新不能用新數據更新單元(電​​池!=無)

+0

那麼,是問題?如果單元格爲!= nil,那麼單元格顯然先前已經通過內部的if塊,因此已經添加了按鈕 -​​ 只需使用它們即可。 – luk2302

+0

請更新您的問題,因爲它很明顯 –

+0

@ luk2302我更新了我的問題。你可以請現在檢查。謝謝 –

回答

4

我的建議是你可以添加按鈕,如果該細胞是零和更改按鈕的數據,如果條件外

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
NSString *CellIdentifier = @"cell"; 
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

if (cell == nil) 
{ 
    cell = [[CustomCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    [cell addButtons:buttonsArray]; // add the buttons 
} 
[cell updateButtonData:dataArray]; // update the data on the button 
[cell renderCell:[self.dataArray objectAtIndex:indexPath.row]]; 
return cell; 
}