用户内容和无限滚动

User content and infinite scroll

有人可以告诉我如何获取用户提交的内容(如 post)并在我使用 infinite scroll.To 时自动将其附加到末尾吗?更具体地说,当我想向下滚动并到达页面末尾,我希望该页面获得更多 post 并显示它们(就像带有新闻提要的 facebook)。谢谢

假设它是一个tableView,当它到达结束单元格时从服务器获取更多数据。

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSInteger index = indexPath.row;
    if (index == yourEndCellIndex) {
        [self fetchMoreDataFromServer];
    }
}

获取服务器数据并将其附加到您的数据数组。

- (void)fetchMoreDataFromServer {
    NSArray *dataFromServer = ....;
    for (id obj in dataFromServer) {
        [self.dataArray addObject:obj];
    }
    [self.tableView reloadData];
}