我在我的ViewController中使用了一个NSManagedObject作为属性,声明如下:
@property(retain, nonatomic)NSManagedObject *person;我正在将fetch的内容传播到UITableView,当用户点击他正在查找的联系人时,会发生以下情况:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
self.person = [contacts objectAtIndex:indexPath.row];Contacts包含获取的结果,该操作如下所示:
NSArray *contactsArray;
NSError *error;
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSManagedObjectContext *context = [(OAuthStarterKitAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];
NSEntityDescription *entity = [NSEntityDescription
entityForName:@"Contacts" inManagedObjectContext:context];
[fetchRequest setEntity:entity];
testForTrue = [NSPredicate predicateWithFormat:@"SOME CONDITION"];
[fetchRequest setPredicate:testForTrue];
[fetchRequest setFetchLimit:10];
contactsArray = [[NSArray alloc]initWithArray:[context executeFetchRequest:fetchRequest error:&error]];当用户点击联系人时,self.person具有该值,但当我尝试在另一种方法中使用该值时,该值为nil,地址为0x000000。这只在iOS 5上发生,在iOS 6上,person具有所选联系人的值,我可以在其他地方使用。
有什么想法吗?
谢谢。
发布于 2013-03-07 17:47:31
而不是获取NSManagedObject,它总是依赖于上下文的生命周期,我只是存储了de NSManagedObjectID,然后使用函数objectWithID获取NSManagedObject。它成功了!
https://stackoverflow.com/questions/15252179
复制相似问题