iphone - 我如何判断 UITableView 是否包含特定的 NSIndexPath?

标签 iphone objective-c ios xcode cocoa-touch

这是我使用的代码:

if (appDelegate.currentMainIndexPath != nil /* && doesPathExistInTableView */)
{
    [tblView scrollToRowAtIndexPath:appDelegate.currentMainIndexPath atScrollPosition:UITableViewScrollPositionTop animated:NO];
    appDelegate.currentMainIndexPath = nil;
}

最佳答案

你可以使用它。将索引路径的行和部分传递给它

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
}

关于iphone - 我如何判断 UITableView 是否包含特定的 NSIndexPath?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10506318/

相关文章:

iphone - 在 Objective-C 中如何在 View Controller 之间传递对象?

iphone - 未显示游戏中心邀请

iphone - iPhone 的定位精度会超出职责范围吗?

objective-c - 是否有一种简单的方法(在 Cocoa/iOS 中)将方法调用排队,以便在下一个运行循环中运行一次?

objective-c - 单击 uitableview 单元格后获取相同的数据

javascript - 滚动时点击 Phonegap 移动应用程序会选择不正确的项目

iphone - ios 查找所有保存的文件

iphone - 如何在下载的同时开始播放AVAudioPlayer?

objective-c - 在没有服务器的情况下在 XCode 3/4 中使用 GIT 或 SVN

ios - 使用子类从 Storyboard 中实例化 View Controller