[英]Warning: Attempt to present <UIImagePickerController> on <MFSideMenuContainerViewController> whose view is not in the window hierarchy
我正在尝试在iOS中加载图片选择器,但在第一次尝试中效果很好,但是当我第二次这样做时,它会给我以下警告
警告:尝试显示不在窗口层次结构中的视图!
我选择图像的代码如下
[self startCameraControllerFromViewController:self usingDelegate:self sourceType:UIImagePickerControllerSourceTypePhotoLibrary];
并且方法如下startCameraControllerFromViewController
- (BOOL) startCameraControllerFromViewController: (UIView*) controller usingDelegate: (id) delegate sourceType:(UIImagePickerControllerSourceType) sourceType{
if (([UIImagePickerController isSourceTypeAvailable:
sourceType] == NO)
|| (delegate == nil)
|| (controller == nil))
{
DLog(@"no is being returned");
return NO;
}
if(_delegate != nil &&[ _delegate respondsToSelector:@selector(imagePickerOpened)]){
[_delegate imagePickerOpened];
}
if(cameraUI==nil){
// [SVProgressHUD showWithStatus:@"Loading"];
[ALERT showLoader];
dispatch_queue_t concurrentQueue=dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(concurrentQueue, ^{
cameraUI = [[UIImagePickerController alloc] init];
cameraUI.sourceType = sourceType;
cameraUI.mediaTypes=cameraUI.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeImage, nil];
cameraUI.allowsEditing = YES;
cameraUI.delegate = delegate;
dispatch_async(dispatch_get_main_queue(), ^{
[self.window.rootViewController presentModalViewController:cameraUI animated:YES];
//[self presentModalViewController:cameraUI animated:YES ];
[ALERT hideLoader];
});
});
}
else{
cameraUI.sourceType = sourceType;
[self.window.rootViewController presentModalViewController:cameraUI animated:YES];
//[self presentModalViewController:cameraUI animated:YES ];
}
return YES;
}
问题与设置根视图控制器有关,我设置了不存在的根视图控制器,因此我将当前视图控制器设置为根视图控制器,从而解决了我的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.