我正在开发一个使用SQLite的应用程序.我想使用分页机制显示用户列表(UITableView).有谁能告诉我,当用户滚动到列表末尾(比如Facebook应用程序主页)时,如何在我的列表中加载更多数据?
我正在开发一个使用SQLite的应用程序.我想使用分页机制显示用户列表(UITableView).有谁能告诉我,当用户滚动到列表末尾(比如Facebook应用程序主页)时,如何在我的列表中加载更多数据?
您可以通过判断您在cellForRowAtIndexPath:
方法中所处的位置来做到这一点.此方法易于理解和实施:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// Classic start method
static NSString *cellIdentifier = @"MyCell";
MyCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell)
{
cell = [[MyCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MainMenuCellIdentifier];
}
MyData *data = [self.dataArray objectAtIndex:indexPath.row];
// Do your cell customisation
// cell.titleLabel.text = data.title;
BOOL lastItemReached = [data isEqual:[[self.dataArray] lastObject]];
if (!lastItemReached && indexPath.row == [self.dataArray count] - 1)
{
[self launchReload];
}
}
编辑:添加了对最后一项的判断,以防止递归调用.您必须实现定义是否已到达最后一项的方法.
EDIT2:我已经联系到你了