2013-10-23 34 views
1

我试图在iOS中加载图片选择器,它在第一次尝试中正常工作,但是当我第二次执行此操作时我有以下警告警告:尝试在<MFSideMenuContainerViewController>上呈现其视图不在窗口层次结构中的<UIImagePickerController>

警告:尝试呈现其视图不在窗口层次结构中!

我采摘图像代码如下

[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; 

}

回答

1

的问题是相关的设定根视图控制器我已经设置了根视图控制器不存在,所以我将我当前的视图控制器设置为根视图控制器,它解决了我的问题。

+0

我不明白你是怎么解决这个问题的?我遇到类似的代码 –

+0

我的代码是相当大的问题,所以不能发布我的整个代码。只是看看你的根视图控制器是什么,并且是相同的根视图控制器,目前我相信他们会不同。 –

相关问题