Attempt to present UIViewController on UIViewController whose view is not in the window hierarchy

后端 未结 30 3134
一整个雨季
一整个雨季 2020-11-21 23:39

Just started using Xcode 4.5 and I got this error in the console:

Warning: Attempt to present < finishViewController: 0x1e56e0a0 > on < ViewCont

30条回答
  •  梦谈多话
    2020-11-21 23:56

    I had the same problem. I had to embed a navigation controller and present the controller through it. Below is the sample code.

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
    
        UIImagePickerController *cameraView = [[UIImagePickerController alloc]init];
        [cameraView setSourceType:UIImagePickerControllerSourceTypeCamera];
        [cameraView setShowsCameraControls:NO];
    
        UIView *cameraOverlay = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 768, 1024)];
        UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"someImage"]];
        [imageView setFrame:CGRectMake(0, 0, 768, 1024)];
        [cameraOverlay addSubview:imageView];
    
        [cameraView setCameraOverlayView:imageView];
    
        [self.navigationController presentViewController:cameraView animated:NO completion:nil];
    //    [self presentViewController:cameraView animated:NO completion:nil]; //this will cause view is not in the window hierarchy error
    
    }
    

提交回复
热议问题