I’m creating a simple app that loads a modal view in the root view controller, and that modal view has a segmented control for a user to choose if he/she wants to stay logged in. The modal view has a username and password field with a submit button below it. After the app verifies the user, he/she will be taken to the root view controller that has buttons to take the user to another view i.e. Feature 1, Feature 2, etc. If the user taps the back button (driven by a navigation controller), I want the user not to be asked again for his/her credentials when the app loads the root view controller again, thus the use of the segmented control.
How can use and implement the segmented control in this case? Thanks!
I assume you’ve realised this, but you need to store the login credentials, I assume your question is ‘How!?’
If you want to store the login credentials for just the lifetime of the app (they are logged out when you close the app), I’d store the variables in Globals class so that they can be referenced from anywhere in the app.
If you want to keep the login credentials stored longer (i.e. they may still be logged in if they close and reopen the app), you should use NSUserDefaults:
Writing:
Reading:
Please also note the following considerations though:
boolForKey:returns NO if the key you provide doesn’t exist