我有几个UIViewControllers,显示我的'用户'对象的表视图作为部分和'网站'对象作为每个部分下的行。网站与用户的关系是一对多的关系。NSFetchResultController委托错误
目前我显示这个数据用下面的代码:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
id <NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:0];
return [sectionInfo numberOfObjects];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
User *sectionUser = (User*)[self.fetchedResultsController objectAtIndexPath:[NSIndexPath indexPathForRow:section inSection:0]];
return [[sectionUser.sitesToUser allObjects] count];
}
在我NSFetchResultsController我只是拉着所有用户对象,没什么特别的。
现在我的问题 - 每当我更新的结果,通过移除部分(即用户)或添加一个用户,而这一观点也打开了,我得到一个NSFetchedResultsController委托错误:
Serious application error. An exception was caught from the delegate of
NSFetchedResultsController during a call to -controllerDidChangeContent:. Invalid
update: invalid number of sections. The number of sections contained in the table
view after the update (2) must be equal to the number of sections contained in the
table view before the update (1), plus or minus the number of sections inserted or
deleted (0 inserted, 0 deleted). with userInfo (null)
我只在我以这种方式显示数据的视图中获取它,是用户是部分,站点在每个部分下是行。
我做的事情真的很愚蠢吗?我认为它会删除该部分,当我删除它等...似乎工作正常,如果每个用户是在UITableView的行 - 我认为这是我的问题的症结...
“网站与用户的关系是一对多的。”它似乎相反。 – an0