我有一个从核心数据中获取数据的表。我添加了一个部分,其中必须只有一个静态单元格。但我得到一个错误,我不知道为什么。
* 由于未捕获的异常“NSRangeException”而终止应用程序,原因:“* -[__NSArrayM objectAtIndex:]: index 1 beyond bounds [0 .. 0]”
questo è il codice
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self setupFetchedResultsController];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 2;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (section == 0) {
return [[self.fetchedResultsController fetchedObjects] count];
} else if (section == 1) {
return 1;
}
return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Category Cell";
CategoryCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[CategoryCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell...
if (indexPath.section == 0) {
NSLog(@"section %i",indexPath.section);
Category *category = [self.fetchedResultsController objectAtIndexPath:indexPath];
cell.categoryNameLabel.text = category.name;
cell.categoryNumberItemsLabel.text = [NSString stringWithFormat:@"%i",category.containItem.count];
} else {
//Static cell
}
return cell;
}