模式显示UIImagePickerController时出错 [英] Error with presenting UIImagePickerController modally
问题描述
我有一个奇怪的问题,在我的iOS 6应用程序中呈现 UIImagePickerController
modally。 XCode
给我这个错误:
I have a strange problem presenting the UIImagePickerController
modally in my iOS 6 app. The XCode
gives me this error:
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;
}
在我的 SGNewMailViewController
我提出了一个新的 UIView
,它是 SGFoldingAttachmentView
的成员,其中有这个代码:
In my SGNewMailViewController
I present a new UIView
, a member of SGFoldingAttachmentView
class which has this code in it:
- (void)choosePhotoPressed {
SGNewMailViewController *mailVC = [((SGAppDelegate *)[UIApplication sharedApplication].delegate).firstViewController.navigationController.viewControllers lastObject];
[mailVC displayCameraRoll];
}
最后,这是我的 SGNewMailViewController
displayCameraRoll
方法:
In the end, here's my 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];
}
}
那么什么可能是问题?是在另一个类提供的自定义视图中吗?我应该如何解决它?提前感谢!
So what can possibly be the problem? Is it in the custom view presented from another class? How should I fix it? Thanks in advance!
推荐答案
让UINavigationController成为您窗口的根视图控制器。这应该解决问题
Make the UINavigationController to be the root view controller of your window. This should fix the problem
self.window.rootViewController = navController;
这篇关于模式显示UIImagePickerController时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!