以模态方式呈现 UIImagePickerController 时出错

Ser*_*yov 3 iphone cocoa-touch objective-c uiview ios

UIImagePickerController在 iOS 6 应用程序中呈现模态时遇到了一个奇怪的问题。该XCode给我这个错误:

Warning: Attempt to present <UIImagePickerController: 0x1e025040> on <UINavigationController: 0x1d51ce00> whose view is not in the window hierarchy!
Run Code Online (Sandbox Code Playgroud)

我有以下窗口层次结构AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window = window;

    firstViewController = [[SGNewMailViewController alloc] init];
    navController = [[UINavigationController alloc] initWithRootViewController:firstViewController];
    self.window.rootViewController = firstViewController;
    [self.window makeKeyAndVisible];
    return YES;
}
Run Code Online (Sandbox Code Playgroud)

在我的SGNewMailViewController我提出了一个 new UIView,一个SGFoldingAttachmentView类的成员,其中包含以下代码:

- (void)choosePhotoPressed {
    SGNewMailViewController *mailVC = [((SGAppDelegate *)[UIApplication sharedApplication].delegate).firstViewController.navigationController.viewControllers lastObject];
    [mailVC displayCameraRoll];
}
Run Code Online (Sandbox Code Playgroud)

最后,这是我的SGNewMailViewController displayCameraRoll方法:

- (void)displayCameraRoll {
    if ([UIImagePickerController isSourceTypeAvailable:
         UIImagePickerControllerSourceTypeSavedPhotosAlbum])
    {
        UIImagePickerController *imagePicker =
        [[UIImagePickerController alloc] init];
        imagePicker.delegate = self;
        imagePicker.sourceType =
        UIImagePickerControllerSourceTypePhotoLibrary;
        imagePicker.mediaTypes = [NSArray arrayWithObjects:
                                  (NSString *) kUTTypeImage,
                                  nil];
        imagePicker.allowsEditing = NO;
        [self presentViewController:imagePicker animated:YES completion:nil];
    }
}
Run Code Online (Sandbox Code Playgroud)

那么可能是什么问题呢?它是否在另一个类提供的自定义视图中?我该如何解决?提前致谢!

Ale*_*iev 5

使 UINavigationController 成为窗口的根视图控制器。这应该可以解决问题

self.window.rootViewController = navController;
Run Code Online (Sandbox Code Playgroud)