以模态方式呈现 UIImagePickerController 时出错

2024-05-24

我有一个奇怪的问题UIImagePickerController在我的 iOS 6 应用程序中以模态方式显示。这XCode给我这个错误:

Warning: Attempt to present <UIImagePickerController: 0x1e025040> on <UINavigationController: 0x1d51ce00> whose view is not in the window hierarchy!

我的窗口层次结构如下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;
}

In my SGNewMailViewController我提出一个新的UIView,成员SGFoldingAttachmentView类中包含以下代码:

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

最后,这是我的SGNewMailViewController displayCameraRoll method:

- (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];
    }
}

那么可能是什么问题呢?它是在另一个类呈现的自定义视图中吗?我应该如何修复它?提前致谢!


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

self.window.rootViewController = navController;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

以模态方式呈现 UIImagePickerController 时出错 的相关文章

随机推荐