我有一個屬性「組」的實體,得到numberOfRowsInSection因爲我要歸入2段我的實體的「組」列表(0或1)如何從NSFetchedResultsController與sectionNameKeyPath
@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;
}
我實現了這個方法,但我回到具體爲2,因爲我要顯示在現場的第一個視圖2個部分,即使沒有記錄但是 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 2; } – iPhoneJavaDev
你不能這樣做。我會爲此添加一個編輯。 –
如果我沒有關於我想組合的實體的任何記錄,我應該如何強制在開始時顯示2個部分? – iPhoneJavaDev