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

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

    You can use this. Pass it indexpath's row and section

    Objective C:

    -(BOOL) isRowPresentInTableView:(int)row withSection:(int)section
    {
        if(section < [self.tableView numberOfSections])
        {
            if(row < [self.tableView numberOfRowsInSection:section])
            {
                return YES;
            }
        }
        return NO;
    }
    

    Swift 3:

    func isRowPresentInTableView(indexPath: IndexPath) -> Bool{
        if indexPath.section < tableView.numberOfSections{
            if indexPath.row < tableView.numberOfRows(inSection: indexPath.section){
                return true
            }
        }
    
        return false
    }
    

提交回复
热议问题