Error while presenting a view controller

104 views Asked by At

I am trying to switch from one view controller to another and I am getting this error:

Warning: Attempt to present on whose view is not in the window hierarchy!

The code I'm using is the following:

view2 *v2 = [[view2 alloc] initWithNibName:nil bundle:nil];
[self presentViewController:v2 animated:YES completion:NULL];
1

There are 1 answers

0
Lorenzo B On BEST ANSWER

Few points here.

You are creating a new view controller passing nil as a parameter of initWithNibName:bundle method. If you pass nil, as per the doc, the nibName property is set to nil. Is this that you want? Where the code is running into? Into another view controller? Into the app delegate?

Classes should start with a capital letter. e.g View2, ViewController2. Variable or properties with camel case notation. e.g. myProperty, myView.

view2 should renamed as ViewController2 (or whatever you want) since it's a controller and not a view.

Finally, what's your goal? When you ask a problem you should describe the context you are running in. On the contrary you should receive downvotes.