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];
Few points here.
You are creating a new view controller passing
nil
as a parameter ofinitWithNibName:bundle
method. If you passnil
, as per the doc, thenibName
property is set tonil
. 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 asViewController2
(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.