Ethan Allen Ethan Allen - 3 months ago 12
Objective-C Question

How can I tell if a UITableView contains a specific NSIndexPath?

Here is the code I'm using:

if (appDelegate.currentMainIndexPath != nil /* && doesPathExistInTableView */)
{
[tblView scrollToRowAtIndexPath:appDelegate.currentMainIndexPath atScrollPosition:UITableViewScrollPositionTop animated:NO];
appDelegate.currentMainIndexPath = nil;
}

Answer

You could try to get UITableViewCell by :

- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath;
// returns nil if cell is not visible or index path is out of range

here's the complete code :

UITableViewCell *cell = [cellForRowAtIndexPath:appDelegate.currentMainIndexPath];

if (appDelegate.currentMainIndexPath != nil && cell !=nil)
{
    [tblView scrollToRowAtIndexPath:appDelegate.currentMainIndexPath atScrollPosition:UITableViewScrollPositionTop animated:NO];
    appDelegate.currentMainIndexPath = nil;
}