How to reload and animate only one cell / row of a UITableView?

How can I reload and animate only one cell / row? I'm uploading some files right now. Each time the file completes the download, I invoke it as a completed delegate and invoke [tableview reload]. But then the whole table is recharged. And how can I animate the table so that it does not blink. For example, the fading effect or so.

welcomes Max

+68
objective-c cocoa-touch uitableview animation
Mar 24 2018-11-11T00:
source share
5 answers

Use the following instance method of a UITableView :

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

You need to specify the NSArray of NSIndexPaths that you want to reload. If you just want to reboot. If you only want to reload a single cell, you can specify an NSArray that contains only NSIndexPath . For example:

 NSIndexPath* rowToReload = [NSIndexPath indexPathForRow:3 inSection:0]; NSArray* rowsToReload = [NSArray arrayWithObjects:rowToReload, nil]; [myUITableView reloadRowsAtIndexPaths:rowsToReload withRowAnimation:UITableViewRowAnimationNone]; 

You can see the UITableViewRowAnimation enumeration for all possible ways of animating row updates. If you do not need animation, you can use the value UITableViewRowAnimationNone , as in the example.

Rebooting certain lines has a greater advantage than just getting the animation effect you want. You also get a huge performance boost, because only those cells that you really need to reload have their data updated, repositioned, and redrawn. Depending on the complexity of your cells, each time you update a cell, there may be enough overhead, so narrowing down the number of updates you make is a necessary optimization that you should use whenever possible.

+182
Mar 24 2018-11-11T00:
source share

If you only need to update the text in the tableview cell.

 UITableViewCell *cell = [_myTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:1]]; cell.textLabel.text = [NSString stringWithFormat:@"%i", (int)_targetMaxDistanceSlider.value]; 
+3
Jun 08 '15 at 17:57
source share

Apple Document did it with new syntax

 [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone]; 
0
Aug 19 '15 at 12:13
source share

To reload specific cells in a tableView with given indexPaths , you need to create an array of indexPaths and then call the reloadRowsAtIndexPaths function on the tableView .

Here is an example:

Swift 5:

 let indexPathsToReload = [indexPath1, indexPath2, indexPath3] tableView.reloadRows(at: indexPathsToReload, with: .none) 

Goal C:

 NSArray *indexPaths = @[indexPath1, indexPath2, indexPath3]; [self.tableView reloadRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationNone]; 

or

 NSArray *indexPaths = [NSArray arraywithobject:@"indexPath1", @"indexPath2", @"indexPath3",nil]; [self.tableView reloadRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationNone]; 
0
Oct 31 '15 at 13:06
source share

swift

You can use

 let selectedIndexPath = IndexPath(item:0 , section: 0) self.tableView.reloadRows(at: [selectedIndexPath], with: .none) 

in order to reload a specific cell.

0
09 Oct '18 at 5:29
source share



All Articles