如何获取NSIndexPath部分中的行数

Ped*_*dro 2 objective-c nsindexpath ios

我想获取NSIndexPath部分中的行数.对于我在这里和Apple的文档中的所有搜索,我找不到如何获得这个值.有什么线索吗?

我的具体目的是使用它来确定所选行是否是该部分中的最后一行,因此如果有人建议通过另一种方法确定该行是一样好的话.

Ind*_*ore 10

一切都在文档中

numberOfRowsInSection:

int rows = [table numberOfRowsInSection:indexPath.section];
Run Code Online (Sandbox Code Playgroud)


Nik*_*uhe 6

唯一的方法是询问表的数据源:

NSUInteger rowCount = [tableView.dataSource tableView:tableView numberOfRowsInSection:indexPath.section];
Run Code Online (Sandbox Code Playgroud)


Eim*_*tas 5

以下是我在我的案例中的表现:

表部分包含存储在其中的对象列表NSArray,因此节中的行数是数组中对象的数量.在你的情况下 - 如果row不是数组中的对象 - 只需进行检查

if ([indexPath row] + 1 == [_objectsArray count]) {
    ...
Run Code Online (Sandbox Code Playgroud)

但是,如果表中的项目未保存在集合中,则只需tableViewdidSelectRow..委托方法中调用对象上的相应方法,即可轻松检索节中的行数:

NSInteger numberOfRows = [tableView numberOfRowsInSection:[indexPath section]];
Run Code Online (Sandbox Code Playgroud)

  • 我喜欢使用数组计数的解决方案,但不应该是[indexPar row] == [_objectsArray count] - 1? (2认同)