我正在开发一个使用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:我已经联系到你了

Ios相关问答推荐

SwiftUI中ForEach和@ State数组的可能并发问题

SwiftUI@Observable不跟踪父类属性中的更改以更新视图

如何在iPhone 15上消除.NET Maui中状态栏和页面之间的差距

如何将 Info.plist 文件添加到 Xcode for admob,错误 添加后会产生多个命令

Toast 不显示 Flutter

如何使用 pushViewController 从 UIHostingController 的 SwiftUI 视图中推送 ViewController?

应用程序被杀死时如何在 flutter ios 应用程序中播放音频?

拔下设备后,DriverKit USB 驱动程序 (dext) 进程不会终止

UIControl 子类 - 按下时显示 UIMenu

更改图标会导致 SwiftUI 动画出现故障?

工具栏底部 iOS 16 - SwiftUI

集成 IDNow SDK 时未找到 Xcode FLAnimatedImage.h 文件问题

iOS 是否支持使用独立 .xib 文件创建的嵌套自定义子视图?

来自 c++ 的runtime_error未在 iOS 中捕获

如何在不同设备的segment控制中管理文本大小(text size)?

UICollectionView - 水平滚动,水平布局?

NSPredicate 用于测试 NULL 和空白字符串

UICollectionView flowLayout 没有正确包装单元格

AVAudioRecorder 抛出错误

UITableView 中的圆形 UIImageView 没有性能影响?