0

我无法弄清楚为什么我在推送之前分配给视图控制器的数据在推送之后变为空。

我正在使用 Core Data 进行存储。该Project对象是一个 NSManagedObject。

这是我的流程:

  1. 在我的主视图控制器中,我启动了一个 UIImagePickerViewController
  2. - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info我写一个文件并将路径保存在核心数据对象中。
  3. 我从核心数据中获取父对象并验证它不为空。
  4. 我关闭了图像选择器视图控制器。
  5. 我实例化另一个视图控制器并将父对象分配给该视图控制器上的一个属性@property (nonatomic, strong) Project * project;
  6. 我推那个新的视图控制器
  7. 在视图控制器的viewDidLoad方法中,对象现在为空。

知道为什么会这样吗?

这是代码:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    // Access the uncropped image from info dictionary
    UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

    ImageInfo * imgInfo = [[DataController sharedController] newImageInfo];

    // Create path to output images
    NSString  *imagePath = [NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat: @"Documents/%@.%@"
                                                                                                       , imgInfo.filename
                                                                                                       , imgInfo.extension]];
    [UIImageJPEGRepresentation(image , 0.5) writeToFile:imagePath atomically:YES];
    imgInfo.path = imagePath;

    AnnotationDocument * annDoc = [[DataController sharedController] newAnnotationDocument];
    [[DataController sharedController] associateImageInfo:imgInfo withAnnotationDocument:annDoc];

    Project * untitledProject = [[DataController sharedController] untitledProject];
    [[DataController sharedController] associateAnnotationDocument:annDoc withProject:untitledProject];
    NSLog( @"UP key: %@" , untitledProject.key );

    [[DataController sharedController] saveContext];
    NSLog( @"UP key: %@" , untitledProject.key );

    [picker dismissModalViewControllerAnimated:NO];

    AnnotationDocListViewController * vc = [[AnnotationDocListViewController alloc] init];
    vc.project = [[DataController sharedController] projectForKey:untitledProject.key];

    [self.navigationController pushViewController:vc animated:YES];
}
4

0 回答 0