【发布时间】:2013-10-21 00:31:12
【问题描述】:
我有一个具有“组”属性的实体,因为我想按“组”(0 或 1)将我的实体列表分为 2 个部分
@property (nonatomic, retain) NSNumber * group;
在我的 fetchedResultsController 中,我将 sectionNameKeyPath 指定为“组”
self.fetchedResultsController = [[NSFetchedResultsController alloc]
initWithFetchRequest:request managedObjectContext:self.managedObjectContext
sectionNameKeyPath:@"group" cacheName:nil];
如何在下面的方法中返回每个部分的行数?我收到以下错误:
Terminating app due to uncaught exception 'NSRangeException', reason:
'-[__NSArrayM objectAtIndex:]: index 1 beyond bounds for empty array'
代码如下:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [[[self.fetchedResultsController sections] objectAtIndex:section]
numberOfObjects];
}
我也试过了,同样的错误:
id <NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections]
objectAtIndex:section];
return [sectionInfo numberOfObjects];
注意我也实现了这个方法:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 2;
}
【问题讨论】:
标签: ios uitableview core-data nsfetchedresultscontroller