iPhone:获取结果 Controller ,不要使用 UITableView 中的部分

标签 iphone uitableview nsfetchedresultscontroller

我正在使用一个获取的结果 Controller ,它似乎想在我的 UITableView 中使用部分进行设置。好吧,在这种情况下,我不想使用部分。将 numberOfSectionsInTableView: 的值设置为 1 很容易。但是,现在我不确定如何获取 numberOfRowsInSection: 将所有单元格返回到一个部分中。

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.
    id <NSFetchedResultsSectionInfo> sectionInfo = [[fetchedResultsController sections] objectAtIndex:section];
    return [sectionInfo numberOfObjects];
}

如何让该方法返回所有单元格,因为我只想使用 1 个部分?

最佳答案

为了使您的获取结果 Controller 避免返回分段对象,您需要按如下方式正确初始化它:

NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:request managedObjectContext:managedObjectContext sectionNameKeyPath:nil cacheName:@"Root"];

这里不会有任何节,因为您传递了 nil 作为 sectionNameKeyPath 的参数。那么,您的 tableView:numberOfRowsInSection 方法是正确的。

关于iPhone:获取结果 Controller ,不要使用 UITableView 中的部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2983129/

相关文章:

iphone - 带有当前 modalviewcontroller 的 UInavigation Controller 在 UItableviewcontroller 中不起作用

ios - TableView reloadData 重启 UITableViewCell 中的 NSTimer

ios - 重用 UITableViewCell 移动 subview 框架

ios swift ResearchKit 使用 NSPredicate 跳过的条件

ios - 以编程方式从 subview 快速返回按键按下事件

ios - 如何打开 UIDocumentPicker 导入的文件?

iphone - 不同实体的多个 NSFetchedResultControllers?

ios - 带有核心数据的慢速 UISearchDisplayController

ios - 我想要一个用于核心数据的通用 fetchedResultsController 来支持多个模型

iphone - 从 HTML 文件链接到 View