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

前端 未结 8 1750
予麋鹿
予麋鹿 2021-02-07 06:27

Here is the code I\'m using:

if (appDelegate.currentMainIndexPath != nil /* && doesPathExistInTableView */)
{
    [tblView scrollToRowAtIndexPath:appDele         


        
8条回答
  •  温柔的废话
    2021-02-07 07:08

    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;
    }
    

提交回复
热议问题