使用nsfetchedresults控制器设置分段表头



我在我的项目中使用NSFetchedResultsController以及core data。我能够从数据库中获取所有对象。我在分段表视图中显示它们。我希望将每个节中的行总数显示为节表视图的标题。我不会得到任何帮助的。我已经尝试了很多,但不知道如何确切地设置它。任何形式的帮助都是值得感激的。

应该这样做:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    NSInteger numberOfRows = [[[self.frc sections] objectAtIndex:section] numberOfObjects];
    UITableViewHeaderFooterView *sectionHeaderView = [[UITableViewHeaderFooterView alloc] init];
    sectionHeaderView.textLabel.text = [NSString stringWithFormat:@"Total objects %d", numberOfRows];
    return sectionHeaderView;
}

技巧是从NSFetchedResultsController中获得正确的部分并在其上调用numberOfObjects方法。NSFetchedResultsController中的section是符合NSFetchedResultsSectionInfo委托的代理对象。

最新更新