【问题标题】:How to split data and reload while scrolling in UITableview?在 UITableview 中滚动时如何拆分数据并重新加载?
【发布时间】:2013-11-09 14:48:19
【问题描述】:

我有 100 条记录要加载到 UITableview 中,最初我只想重新加载前 25 条记录,当我们在 25 条记录后滚动 tableview 时,表想要重新加载接下来的 25 条记录,就像我想对 ios 中的所有记录一样。我怎样才能做到这一点?有人帮帮我吗?

【问题讨论】:

  • 记录从何而来?如果您在本地拥有所有数据,则根本没有理由这样做。
  • UITableView 将为仅可见单元格创建单元格实例,剩余单元格将在向上或向下滚动后出列。因此无需按照您的意愿进行操作。

标签: ios uitableview reload


【解决方案1】:

row_count 声明为int。在viewDidLoad 中设置row_count = 25; 然后numberOfRowsInSectionreturn [table_array count]; 替换为return row_count; 然后在scrollViewDidScroll 中使用我的代码添加我的方法

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        return row_count;
    } 

- (void)scrollViewDidScroll:(UIScrollView *)aScrollView {
        CGPoint offset = aScrollView.contentOffset;  
        CGRect bounds = aScrollView.bounds;
        CGSize size = aScrollView.contentSize;
        NSLog(@"%@", NSStringFromCGSize(size));
        UIEdgeInsets inset = aScrollView.contentInset;
        float y = offset.y + bounds.size.height - inset.bottom;
        float h = size.height;
            float reload_distance = 10;
        if(y > h + reload_distance) {
            row_count = (row_count + 25 > [table_array count])?[table_array count]:row_count + 25;        
            [Yourtable reloadData];
        }
    }

这样设置..它会根据需要加载您的数据

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-06
    • 1970-01-01
    • 2016-10-03
    • 1970-01-01
    相关资源
    最近更新 更多