【发布时间】:2012-03-27 18:14:24
【问题描述】:
当我尝试从表视图中删除一行时,我的tableView 崩溃了。该方法被正确调用,因为在数据库中正确进行了更改。我收到的错误是:
无效更新:第 0 节中的行数无效。
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = [delegate managedObjectContext];
NSManagedObject *objectToDelete = [fixedArray objectAtIndex:indexPath.row];
[context deleteObject:objectToDelete];
[delegate saveContext];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
fixedArray = ([self mondayData]); // this is fetching the data for the array that I supply to the table view
[self.tableView numberOfRowsInSection:[fixedArray count]];
[self.tableView reloadData];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [fixedArray count];
}
【问题讨论】:
-
你能出示
tableView:numberOfRowsInSection:的代码吗? -
我已经更新了原始帖子以显示 section 方法中的行数,并显示我在编辑后返回正确行数的尝试,但不幸的是结果相同。
标签: iphone ios uitableview core-data