次のように宣言された ViewController 内の属性として NSManagedObject を使用しています。
@property(retain, nonatomic)NSManagedObject *person;
ユーザーが探している連絡先をタップすると、フェッチの内容を 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 では、人は選択された連絡先の値を持っており、他の場所で使用できます。
何か案は?
ありがとう。