【发布时间】:2013-12-07 07:22:56
【问题描述】:
我正在使用具有两个不同实体的核心数据
用户信息。 - 名字、姓氏、城市等
电话号码 - 号码
用户信息和电话号码我已经给了很多关系
-(NSArray*)getAllPhoneBookRecords
{
// initializing NSFetchRequest
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
//Setting Entity to be Queried
NSEntityDescription *entity = [NSEntityDescription entityForName:@"userinformation"
inManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:entity];
NSError* error;
// Query on managedObjectContext With Generated fetchRequest
NSArray *fetchedRecords = [self.managedObjectContext executeFetchRequest:fetchRequest error:&error];
for (NSManagedObject *info in fetchedRecords)
{
NSLog(@"city name: %@", [info valueForKey:@"city"]);
NSLog(@"first name: %@", [info valueForKey:@"firstName"]);
NSLog(@"Last name: %@", [info valueForKey:@"lastName"]);
NSLog(@"first phonenumber is %@",[info valueForKey:@"number"]);
}
我已经调用了这个方法
AppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
self.managedObjectContext = appDelegate.managedObjectContext;
self.fetchedRecordsArray = [[appDelegate getAllPhoneBookRecords]mutableCopy];
但它只显示第一个表数据,而不是它来
NSLog(@"first phonenumber is %@",[info valueForKey:@"number"]);
由于未捕获的异常“NSUnknownKeyException”而显示正在终止应用程序,原因:
'[<userinforamtion 0x84691b0> valueForUndefinedKey:]: the entity userinforamtion is not key value coding- compliant for the key "number
但在电话号码实体中,我采用了数字属性
我在用户信息和电话号码之间做错了吗?
【问题讨论】:
标签: iphone objective-c ipad core-data