[英]How to split data and reload while scrolling in UITableview?
我有100條記錄要加載到UITableview中,最初我只想重新加載前25條記錄,而當我們在25條記錄后滾動tableview時,表想要重新加載接下來的25條記錄,就像我想為ios中的所有記錄所做的那樣。我這樣做嗎? 有人幫我嗎?
將row_count
聲明為int。 在viewDidLoad
設置row_count = 25;
然后用numberOfRowsInSection
替換return [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];
}
}
像這樣設置。它將根據需要加載數據
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.