【发布时间】:2013-05-02 18:36:14
【问题描述】:
我有一个应用程序,我试图在其中选择程序所依赖的资源(建筑物、IT 系统)。 Entities之间的关系是Resource.resourceusedonprogProgramme.usesresource。数据模型的一部分在这里:
我正在尝试在 UITableViewController 上使用多个复选标记选择,其中特定程序使用了哪些资源。但是,当我尝试与表中的资源单元格交互时,应用程序崩溃并出现错误
CoreData:错误:严重的应用程序错误。异常被捕获 在核心数据更改处理期间。这通常是一个错误 NSManagedObjectContextObjectsDidChangeNotification 的观察者。这 ALL 或 ANY 运算符的左侧必须是 NSArray 或 一个 NSSet。与 userInfo (null)
我的代码如下:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Resource Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell...
Resource *resource = [self.fetchedResultsController objectAtIndexPath:indexPath];
NSString *fullname = [NSString stringWithFormat:@"%@ %@", resource.hasmanager.firstname, resource.hasmanager.surname];
cell.textLabel.text = resource.name;
cell.detailTextLabel.text = fullname;
if (resource.resourceusedonprog == selectedProgramme){ cell.accessoryType = UITableViewCellAccessoryCheckmark;}
else {cell.accessoryType = UITableViewCellAccessoryNone;}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)path {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:path];
Resource *resource = [self.fetchedResultsController objectAtIndexPath:path];
if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
cell.accessoryType = UITableViewCellAccessoryNone;
resource.resourceusedonprog = NULL;
} else {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
resource.resourceusedonprog = selectedProgramme;
} }
错误似乎是由resource.resourceusedonprog = selectedProgramme触发的;和resource.resourceusedonprog = NULL;事件。如果我将它们注释掉,我可以检查和取消选中单元格(但显然,不会更改 resource.resourceusedonprog 的状态,即我想要实现的目标)。
【问题讨论】:
标签: uitableview core-data relationship