ios - 如何像 iOS 中的 Pinterest 应用程序一样刷新表格 View 而不会出现任何问题

标签 ios uitableview

我正在使用休息服务从服务器获取数据。当我获取所有数据时,我会刷新 TableView 。我正在逐页获取,就像在 Pinterest 应用程序中一样,当 TableView 使用滚动到达最后一行时,它会获取下一页的数据。但是,如果您查看 Pinterest 应用程序,它非常流畅并且没有卡顿(可能是他们使用滚动而不是表格),但在我的应用程序中,它在为下一页获取数据时显示卡顿。

我使用非常普通的方法获取数据并重新加载表 [myTable reloadData],所以这就是为什么不在这个问题中添加代码。所以请建议我更好的方法来使这一切顺利。提前致谢。

最佳答案

您可以尝试简单地将新行添加到 TableView :

insertRowsAtIndexPaths:withRowAnimation:

例如:

NSMutableArray* indexPaths = [NSMutableArray array];
for (short i = X; i < X + N; ++i)
    [indexPaths addObject:[NSIndexPath indexPathForRow:i inSection:0]];

[self.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationBottom];

如您所见,我只是将新的 indexPaths 添加到表中(我假设只有一个部分)。

这将强制 TableView 通过显示新行来刷新其内容——请记住,您的数据源委托(delegate)必须能够为新行提供数据,否则应用程序将崩溃。

关于ios - 如何像 iOS 中的 Pinterest 应用程序一样刷新表格 View 而不会出现任何问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25365023/

相关文章:

uitableview - ABTableViewCell 选中滞后

ios - 在 Swift 中的 View Controller 之间传递数据

ios - Swift:如何使选项卡 View Controller 按钮不显示?

ios - 'NSInternalInconsistencyException',原因 : 'attempt to insert row 0 into section 0, but there are only 0 rows in section 0 after the update'

ios - UITableView行被删除但没有隐藏

uitableview - 如何最初在UITableView中选择一行

根据自动调整大小掩码,UITableViewCellContentView 宽度始终为零(仅在 iOS 7 上)

iphone - 您可以更改在 iOS 的 safari 中更改方向时显示的内容吗?

ios - 如何使用自定义复选框按钮选择 TableView 行选择?

ios - 如何使用 Swift 对字典数据进行分组