본문 바로가기
모바일개발(Mobile Dev)/IOS개발(ObjectC)

[ERROR]whose view is not in the window hierarchy modal

by 테크한스 2015. 12. 19.
반응형




Probably, like me, you have a wrong root viewController

I want to display a ViewController in a non-UIViewController context,

So I can't use such code:

[self presentViewController:]

So, I get a UIViewController:

[[[[UIApplication sharedApplication] delegate] window] rootViewController]

For some reason (logical bug), the rootViewController is something other than expected (a normal UIViewController). Then I correct the bug, replacing rootViewController with a UINavigationController, and the problem is gone.

shareimprove this answer
   
Works like charm – Alejandro Luengo Mar 5 at 21:29

Another potential cause:

I had this issue when I was accidentally presenting the same view controller twice. (Once with performSegueWithIdentifer:sender: which was called when the button was pressed, and a second time with a segue connected directly to the button).

Effectively, two segues were firing at the same time, and I got the error: Attempt to present X on Y whose view is not in the window hierarchy!

shareimprove this answer
2 
I had the same error, and your answer here helped me figure out what was going on, it was indeed this error, fixed it because of you sir, thank you, +1 – samouray May 12 at 7:39
   
I deleted the old segue and connected VC to VC. Is there a way to connect the button to the storyBoard to the VC because that way just keeps erroring for me? – MCB Jul 16 at 22:25

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

}
shareimprove this answer




 [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






반응형

'모바일개발(Mobile Dev) > IOS개발(ObjectC)' 카테고리의 다른 글

Auto Layout Tutorial  (0) 2015.12.22
For foreigner about taxinfo in itunesconnect  (0) 2015.12.22
Using Unwind Segues  (0) 2015.12.19
Introduction to Auto Layout  (0) 2015.12.16
아이폰6, 아이폰6+의 해상도  (0) 2015.12.16