繁体   English   中英

如何获取iOS中的最后一个单元格索引路径?

[英]How to get last cell index path in iOS?

我正在使用tableView构建一个IOS应用程序。 现在,当我到达最后一个cell我从localDB加载了+10数据。

提取数据后,我重新加载了不需要重新加载的tableView ,我想使用更新的tableView 对于那个SOF建议我下面的代码。

[[self tableView] beginUpdates];

[[self tableView] reloadRowsAtIndexPaths:____ withRowAnimation:UITableViewRowAnimationAutomatic];

[[self tableView] endUpdates];

我在reloadRowsAtIndexPaths值中不应该有什么。 请帮助我理解上面的代码行。

您可以像这样在最后一节中获取最后一行的indexPath。

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:(numberOfRowsInLastSection - 1) inSection:(numberOfSections - 1)];

在这里,numberOfSections是您从numberOfSectionsInTableView:方法返回的值。 并且,numberOfRowsInLastSection是您从numberOfRowsInSection:方法返回的表视图最后一部分的值。

您不需要重新加载单元格,因为第10个单元格之后没有单元格。 您希望用户在新闻应用程序中到达最后一个单元时看到更多单元。 解决方案是在下面插入更多行,方法如下:

1-创建要插入的行

NSMutableArray *newRows = @[[NSIndexPath indexPathForRow:10 inSection:0]];


3-更新您的数据源阵列
2- [self.tableView insertRowsAtIndexPaths: newRows, UITableViewRowAnimationAutomatic];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM