kkeith29
kkeith29

Reputation: 33

iOS Development - Using rootViewController correctly

I have been learning iOS development for a few days now. At this moment, I have questions over how the rootViewController is to be used. I searched the web for 3 hours yesterday looking for the answer which turned up quite a few results that never really answered my question.

I am trying to learn to program an app using code only (no storyboards/xib files). I currently am trying to understand how to properly switch between views without using the UINavigationController. In my project I have the main delegate which creates the window, initializes my main view controller (which loads the separate view as well) and adds it as the rootViewController.

My first view has a button which calls a function in its controller to switch to my next view. Here is where my question arises: Do I switch the main rootViewController to the next view or do I load the next view as a subview of the rootViewController? Is the rootViewController supposed to encase all the views for an application? (I think this is how the UINavigationController works)

I have gotten switching of the rootViewController to work in my app, but I want to make sure there isn't some other way I am suppose to manage my views.

Upvotes: 1

Views: 1131

Answers (1)

Alan Moore
Alan Moore

Reputation: 6575

I would not switch the rootViewController, I think that should remain stable. So you could add it as a subview, or you can present it as a modal view.

And of course, you can just change the rootViewController to point to your new view if that's how you want to do it.

Upvotes: 1

Related Questions