Reputation: 708
I need to show an UIScrollView with some pages for present the app to user when launched for the first time. My slides are working correctly, lefting the logic to present it. Is a good practice to set the UIScrollViewController as root controller and set a NSUserDefault variable to control the presentation and redirect to main controller or set the main ViewController as root normally and call the presentation view if needed is a better approach? If there is a better way to do this can someone help? Thanks.
Upvotes: 1
Views: 401
Reputation: 13661
The default behavior of your app is to not present the introduction slides. They are presented only the first time you launch it.
To make the decision of presenting those slides, you ask the question
Is it the first time the app is launched ?
If you put it in your introduction view controller, you will not be able to present it from a button somewhere else in your app (ie a button tutorial
or something).
By putting the presentation logic outside of your view controller, you leave it with only the responsibility of managing its content, and get better separation of concerns.
If you had a login view controller, that takes care of logging in the user. A way to think about this behavior would be the user logs in once, and then I want to skip this view controller every time, and so the logic of presenting it should belong in another view controller. But in that case, logging in will probably have consequences on the rest of your app (setting the Authorization
header of you networking library for exemple). In this case I would set it as the first view controller of the app but skip the UI if we have an auth-token stored in the user defaults, therefore following the former proposition you made. Futhermore, in the context of a navigation controller, it makes sense having this view controller as the root, as you will easily be able to popToRootViewController
if your user ever needs to log-out (or the session token expires)
Upvotes: 2
Reputation: 852
I suggest setting your main view as the default, since 99.99% of the time this is what will be used. Use NSUserDefault to set a bool if this was shown, maybe didShowFirstRun. Then in your main controller, check what the value of that NSUserDefault and show if its nil or false.
In your AppDelegate in the application didFinishLaunchingWithOptions you could check if didShowFirstRun is nil and set a default value to NO.
Don't design around the exception to the app workflow, showing a first run would be the exception.
I have an app that after the login view is shown, it checks for first run and show the getting started screen, then after that has completed, sets the NSUserDefault var and I am done.
Upvotes: 1