如何在UITableview中滚动时分割数据和重新加载?

时间:2013-10-30 06:28:28

标签: ios uitableview reload

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

1 个答案:

答案 0 :(得分: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];
        }
    }

设置如下..它会根据需要加载您的数据