In my code when user adds a new item to the list, the App adds it to an array of items, sorts them, then calls [tableView reloadData]
. Because of sorting the list, sometimes newly added item goes out of view. I'm going to get the UITableViewCell
of newly added item when it's out of view and scroll it back into view.
In cellForRowAtIndexPath
I add the record to tag of each cell:
cell.tag = listItems.recordID;
In addNewItem
method after adding new item and sorting the items:
for (int i = 0; i<listItems.count; i++)
{
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0];
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
int tag = cell.tag;
if (tag == newItemRecordID)
[self.tableView scrollToRowAtIndexPath:indexPath
atScrollPosition:UITableViewScrollPositionMiddle
animated:YES];
}
When the cell is out of view tag
property returns 0
and I can't get the cell.
How is it possible do get that cell?