如何在iOS中获取最后一个单元格索引路径?
我正在使用如何在iOS中获取最后一个单元格索引路径?,ios,objective-c,uitableview,indexing,Ios,Objective C,Uitableview,Indexing,我正在使用tableView构建一个IOS应用程序。现在,当我到达最后一个单元格时,我从localDB加载+10个数据 获取数据后,我重新加载了不需要的tableView,以代替重新加载,我希望使用更新的tableView。对于SOF建议我的以下代码 [[self tableView] beginUpdates]; [[self tableView] reloadRowsAtIndexPaths:____ withRowAnimation:UITableViewRowAnimationAuto
tableView
构建一个IOS
应用程序。现在,当我到达最后一个单元格时,我从localDB加载+10个数据
获取数据后,我重新加载了不需要的tableView
,以代替重新加载,我希望使用更新的tableView
。对于SOF建议我的以下代码
[[self tableView] beginUpdates];
[[self tableView] reloadRowsAtIndexPaths:____ withRowAnimation:UITableViewRowAnimationAutomatic];
[[self tableView] endUpdates];
我不知道reloadRowsAtIndexPaths
value中应该有什么。请帮助我理解上面这行代码。您可以像这样获得最后一节中最后一行的indexPath
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:(numberOfRowsInLastSection - 1) inSection:(numberOfSections - 1)];
这里,numberOfSections是从NumberOfSectionsTableView:method返回的值。numberOfRowsInLastSection是表视图中最后一个部分的numberOfRowsInSection:方法返回的值。您不需要重新加载单元格,因为第10个单元格之后没有单元格。您希望用户在进入最后一个单元格时看到更多单元格,就像在新闻应用程序中一样。解决方案是在下面插入更多行,如下所示:
1-创建要插入的行
NSMutableArray *newRows = @[[NSIndexPath indexPathForRow:10 inSection:0]];
3-更新数据源阵列
2-[self.tableView insertRowsAtIndexPaths:newRows,uitableview行动画自动]代码>这是出现的错误-'NSInternalInconsistencyException',原因:'尝试从第1节中删除第15行,但在更新之前只有1节'***第一次抛出调用堆栈:您将在此处获得您从NumberOfCellsTableView返回的答案?