簡體   English   中英

在UITableview中滾動時如何拆分數據並重新加載?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM