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

前端 未结 8 1744
予麋鹿
予麋鹿 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;
    }
    
    0 讨论(0)
  • 2021-02-07 07:29

    You can also use UITableView's numberOfRowsInSection method.

    0 讨论(0)
提交回复
热议问题