17

Possible Duplicate:
Is it possible to refresh a single UITableViewCell in a UITableView?

In a sequence I am updating only a particular object in my list data(NSMUtableArray), once updated its value, To make the GUI update, I was reloaded the full table like below...

[table reloadData];

It worked fine, However in efficiency point, it is hanging little bit while I am scrolling, Is there any way to update only a particular cell without reload full table?

thanks.

Community
  • 1
  • 1
Newbee
  • 3,231
  • 7
  • 42
  • 74
  • 2
    You can check this if it helps solve your problem http://stackoverflow.com/questions/7040740/reload-spefic-table-cell-ios – Rushi Feb 05 '13 at 07:29

6 Answers6

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

Use this

amar
  • 4,285
  • 8
  • 40
  • 52
9

You can use this..

NSArray *indexPathArray = [NSArray arrayWithObject:[NSIndexPath indexPathForRow:1 inSection:0]];
//You can add one or more indexPath in this array...

[tblview reloadRowsAtIndexPaths:indexPathArray withRowAnimation:UITableViewRowAnimationFade];
Scorpian Alive
  • 734
  • 8
  • 21
2

You can get the cell object by -

UITableViewCell *cell = [table cellForRowAtIndexPath:indexPath];

now change its related values as per your object from data array. It should reflect in the table. Hope this helps.

Nameet
  • 650
  • 8
  • 20
2

You can reload particular image row using index path .

    [mainTableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
                         withRowAnimation:UITableViewRowAnimationNone];
Rajneesh071
  • 30,846
  • 15
  • 61
  • 74
1

As you are making a GUI update, it's better to use reloadData rather then using any other methods. reloadData is the best way in your case to update the UITableView as it avoids inconsistency. The other thing which you can do is, you can add a condition in your cellForRowAtIndexPath and let execution happen only for the cell which is modified.

Rushi
  • 4,553
  • 4
  • 33
  • 46
  • 2
    This is wrong. There are several ways to updates parts of a UITableView. reloadRowsAtIndexPaths, reloadSections and reloadSectionsWithIndexTitles will all reload parts of a UITableView. – Fogmeister Feb 05 '13 at 07:40
  • 1
    @Fogmeister my sentence is incorrect. I meant to say the condition in which Newbee is trying to use it. I've edited my answer. – Rushi Feb 05 '13 at 07:44
0

If you're just adding one item, and you wish to have that added to the table, you can manually insert it into your UITableView, here's an example:

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:_directions.count-1 inSection:0];
NSArray *indexPaths = [NSArray arrayWithObject:indexPath];
[self.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:YES];
David Chavez
  • 125
  • 1
  • 1
  • 9