亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

UITableView無限滾動

UITableView無限滾動

慕慕森 2019-12-17 10:43:24
如何在中無限滾動UITableView?我知道如何使用來完成此操作UIScrollView,其中WWDC的視頻中已經演示了蘋果。我嘗試在執行以下操作tableView:cellForRowAtIndexPath::if (indexPath.row == [self.newsFeedData_ count] - 1){    [self.newsFeedData_ addObjectsFromArray:self.newsFeedData_];    [self.tableView reloadData];}但這失敗了。還有其他想法嗎?
查看完整描述

3 回答

?
MMMHUHU

TA貢獻1834條經驗 獲得超8個贊

如果您需要知道何時到達UITableView的底部,請成為它的委托(因為它是UIScrollView的子類),然后使用-scrollViewDidScroll:委托方法比較表的內容高度和實際滾動位置。


編輯(類似這樣):


- (void)scrollViewDidScroll:(UIScrollView *)scrollView_ 

{   

    CGFloat actualPosition = scrollView_.contentOffset.y;

    CGFloat contentHeight = scrollView_.contentSize.height - (someArbitraryNumber);

    if (actualPosition >= contentHeight) {

        [self.newsFeedData_ addObjectsFromArray:self.newsFeedData_];

        [self.tableView reloadData];

     }

}


查看完整回答
反對 回復 2019-12-17
?
偶然的你

TA貢獻1841條經驗 獲得超3個贊

這是我放在一起的無限滾動UITableView的非??焖俸屯暾难菔?..


@interface InfiniteScrollViewController ()


@property (nonatomic) NSMutableArray *tableViewData;

@property (nonatomic) BOOL loadingMoreTableViewData;


@end


@implementation InfiniteScrollViewController


- (void)viewDidLoad {

    self.tableViewData = [[NSMutableArray alloc] init];

    [self addSomeMoreEntriesToTableView];

}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return self.tableViewData.count + 1;

}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {

        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

    }


    if (indexPath.row < self.tableViewData.count) {

        cell.textLabel.text = [self.tableViewData objectAtIndex:indexPath.row];

    } else {

        cell.textLabel.text = @"Loading more data...";


        // User has scrolled to the bottom of the list of available data so simulate loading some more if we aren't already

        if (!self.loadingMoreTableViewData) {

            self.loadingMoreTableViewData = YES;

            [self performSelector:@selector(addSomeMoreEntriesToTableView) withObject:nil afterDelay:5.0f];

        }

    }


    return cell;

}


- (void)addSomeMoreEntriesToTableView {

    int loopTill = self.tableViewData.count + 20;

    while (self.tableViewData.count < loopTill) {

        [self.tableViewData addObject:[NSString stringWithFormat:@"%i", self.tableViewData.count]];

    };

    self.loadingMoreTableViewData = NO;

    [self.tableView reloadData];

}


@end


查看完整回答
反對 回復 2019-12-17
  • 3 回答
  • 0 關注
  • 810 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號