2013-04-11 62 views
0

我在我的项目中使用NSFetchedResultsController以及核心数据。我能够从数据库中获取所有对象。我在分段表格视图中显示它们。我想在每个部分中显示行的总数作为部分表视图的标题。我没有得到任何帮助。我尝试了很多,但不知道如何设置它。任何形式的帮助都是可观的。使用nsfetchedresults控制器设置分段表头

+0

结帐这个苹果示例代码可能会有所帮助:-http://developer.apple.com/library/ios/#samplecode/DateSectionTitles/Introduction/Intro.html#//apple_ref/doc/uid/DTS40009939 – Leena 2013-04-11 06:13:33

回答

1

类似下面应该工作:

- (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中的部分是符合NSFetchedResultsSectionInfo委托的代理对象。