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

前端 未结 8 1747
予麋鹿
予麋鹿 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:21

    This is how you do it:

    indexPath.row < [self.tableView numberOfRowsInSection:indexPath.section]
    

    In context:

    if (indexPath.row < [self.tableView numberOfRowsInSection:indexPath.section]) {
        [self.tableView scrollToRowAtIndexPath:indexPath
                              atScrollPosition:UITableViewScrollPositionTop
                                      animated:YES];
    }
    

    Inserted into your code:

    if (appDelegate.currentMainIndexPath != nil &&
        indexPath.row < [tblView numberOfRowsInSection:indexPath.section]) {
        [tblView scrollToRowAtIndexPath:appDelegate.currentMainIndexPath
                       atScrollPosition:UITableViewScrollPositionTop
                               animated:NO];
        appDelegate.currentMainIndexPath = nil;
    }
    

提交回复
热议问题