xiz*_*zor 12 xcode core-data objective-c ios
目前我的所有保存都将转到内存中,但不会写入磁盘(iOS).我的应用程序设置为UITableView带有一个添加模态视图,用于创建内容,当用户完成创建内容并单击保存按钮时,新项目(由我的CoreData模型创建的NSManagedObject类)我打印出来并且完全填写.在此之后我立即尝试将其保存到磁盘,并生成一个错误消息,其中包含相同的对象ID,但字段为nil.然而,在我之间的UITableViews (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
方法被调用,即记录@"CanEdit".
谁能看到我做错了什么?
这是代码
NSLog(@"newItem %@", newItem);
NSError *error;
if (![newItem.managedObjectContext save:&error]) {
// Handle the error.
NSLog(@"%@", error);
}
if (editItem) {
[self.navigationController popViewControllerAnimated:YES];
} else {
[self dismissModalViewControllerAnimated:YES];
}
Run Code Online (Sandbox Code Playgroud)
这是我的错误
2011-10-22 15:24:46.322 App[42115:fb03] newItem <Item: 0x81a4a30> (entity: Item; id: 0x81a0ab0 <x-coredata:///Item/t7F2B54D2-0DCC-4530-88D5-900BE25C7DC23> ; data: {
containedIn = "0x6e89010 <x-coredata:///Item/t7F2B54D2-0DCC-4530-88D5-900BE25C7DC22>";
contains = (
);
content = a;
dateLastUsed = nil;
depth = 0;
encrypted = 0;
favorite = 0;
favoritePosition = nil;
folder = 0;
fullPath = "^Templates^Add Title";
name = a;
sortPosition = 0;
})
2011-10-22 15:24:46.323 App[42115:fb03] CanEdit
2011-10-22 15:24:46.326 App[42115:fb03] Error Domain=NSCocoaErrorDomain Code=1570 "The operation couldn’t be completed. (Cocoa error 1570.)" UserInfo=0x6ecc490
{NSValidationErrorObject=<Item: 0x6e88fb0> (entity: Item; id: 0x6e89010 <x-coredata:///Item/t7F2B54D2-0DCC-4530-88D5-900BE25C7DC22> ; data: {
containedIn = nil;
contains = (
"0x81a0ab0 <x-coredata:///Item/t7F2B54D2-0DCC-4530-88D5-900BE25C7DC23>"
);
content = nil;
dateLastUsed = nil;
depth = 0;
encrypted = 0;
favorite = 0;
favoritePosition = nil;
folder = 1;
fullPath = "^Templates^";
name = Templates;
sortPosition = 0;
}), NSValidationErrorKey=content, NSLocalizedDescription=The operation couldn’t be completed. (Cocoa error 1570.)}
Run Code Online (Sandbox Code Playgroud)
log*_*ell 26
问题是您的上下文中有一个MO,其中必填字段设置为nil.具体来说,这就是说NSValidationErrorKey=content前面的内容NSValidationErrorObject是打印为零.
您有一个逻辑错误,其中您的值未正确设置在MO中,或者您应该更改模型以使该字段可选.
| 归档时间: |
|
| 查看次数: |
10373 次 |
| 最近记录: |