我有一個應用程序,我試圖選擇程序依賴的資源(建築,IT系統)。實體之間的關係是Resource.resourceusedonprog < < ---> Programme.usesresource。一片數據模型在這裏: UITableView使用複選標記填充核心數據一對多關係 - CoreData:錯誤:嚴重的應用程序錯誤
我想在一個特定的程序使用資源的UITableViewController上使用多個複選標記選擇。然而,當我嘗試在表中的資源細胞相互作用的應用程序崩潰與錯誤
CoreData: error: Serious application error. Exception was caught during Core Data change processing. This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification. The left hand side for an ALL or ANY operator must be either an NSArray or an NSSet. with 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;
} }
的錯誤似乎是由資源被觸發。 resourceusedonprog = selectedProgramme;和resource.resourceusedonprog = NULL;事件。如果我將它們註釋掉,我可以檢查並取消選中單元格(但顯然,不會更改resource.resourceusedonprog的狀態,即我試圖實現的目標)。