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

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

    There is a more convenient method to tell if a indexPath is valid:

    For Swift 3.0:

    open func rectForRow(at indexPath: IndexPath) -> CGRect
    

    For Objective-C

    - (CGRect)rectForRowAtIndexPath:(NSIndexPath *)indexPath;
    

    You will get CGRectZero if the indexPath is invalid.

    func isIndexPathValid(indexPath: IndexPath) -> Bool {
        return !tableView.rectForRow(at: indexPath).equalTo(CGRect.zero)
    }
    

提交回复
热议问题