【问题标题】:UITableView Load more without reload complete tableUITableView 加载更多而不重新加载完整表
【发布时间】:2016-12-11 18:41:23
【问题描述】:

在 UITableView 的末尾添加新行以保持平滑滚动的更好选择是什么。

选项 1 - insertRowsAtIndexPaths 选项 2 - 重新加载数据

如果我使用 reloadData,UITableView 会闪烁几秒钟并影响平滑滚动。

当用户将表格滚动到底部时,我正在尝试在 UITableView 中实现“加载更多”功能。 Web 服务用于通过对 Load More 行的异步调用来获取数据。

【问题讨论】:

  • 选项 1 - insertRowsAtIndexPaths 是加载更多的更好选择。您也可以添加动画。
  • 能否请您帮助我们提供几行代码来实现 insertRowsAtIndexPaths
  • 请检查我的回答。
  • 如果有帮助,请接受答案。这就是我们的动力。
  • 你有没有试过给定的解决方案?实际上我知道实施,但我正在根据实际实施寻找一些确认。一旦我实现它,我们就有一些具有公共组件的复杂代码结构,如果它提高了性能,我肯定会接受你的回答。谢谢

标签: performance uitableview scroll flicker smooth-scrolling


【解决方案1】:

在您获得网络服务响应的地方添加此代码。

 NSMutableArray *indexPaths = [NSMutableArray array];
    NSInteger currentCount = self.datasource.count;
    for (int i = 0; i < dataToAdd.count; i++) {
        [indexPaths addObject:[NSIndexPath indexPathForRow:currentCount+i inSection:0]];
    }

    // do the insertion
    [self.dataSource addObjects:dataToAdd];

    // tell the table view to update (at all of the inserted index paths)
    [self.tableView beginUpdates];
    [self.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationLeft];
    [self.tableView endUpdates];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-18
    • 2016-04-19
    • 1970-01-01
    相关资源
    最近更新 更多