Reload specific UITableView cell in iOS

后端 未结 3 1457
时光取名叫无心
时光取名叫无心 2020-12-05 04:58

I have a UITableView. I want to update the table data based on selection made. Right now I use [mytable reloadData]; I want to know if there is any

相关标签:
3条回答
  • 2020-12-05 05:41

    I think you're looking for this method of UITableView:

     - (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation
    
    0 讨论(0)
  • 2020-12-05 05:50

    For iOS 3.0 and above, you just have to call :

    - (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;
    

    To reload row 3 of section 2 and row 4 of section 3 for example, you'll have to do this :

    // Build the two index paths
    NSIndexPath* indexPath1 = [NSIndexPath indexPathForRow:3 inSection:2];
    NSIndexPath* indexPath2 = [NSIndexPath indexPathForRow:4 inSection:3];
    // Add them in an index path array
    NSArray* indexArray = [NSArray arrayWithObjects:indexPath1, indexPath2, nil];
    // Launch reload for the two index path
    [self.tableView reloadRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationFade];
    
    0 讨论(0)
  • 2020-12-05 05:50

    You can also get a reference to the UITableViewCell object and change its labels, etc.

    UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
    cell.textLabel.text = @"Hey, I've changed!";
    
    0 讨论(0)
提交回复
热议问题