Quote:
Originally Posted by ChrisYates
Hi,
This is probably easy but bear with me as I am new to iPhone development.
I'm presuming I need to do this in an array but can't figure out the method.
Basically I want to save the text in a UILabel once a user quits out of the application. The idea is that once the user relaunches the app, I can get the text from the UI label (whatever it was before quitting) and display a different view based on what the content of the UI label is.
So in other words if the UILabel said 'One' (before quitting) then on relaunch View1 would show and if the UILabel said 'Two' (before quitting) then on relaunch View2 would show etc etc.
Thanks for any help.
|
Well, you are first going to want to get the text of the label into an NSString.
Code:
NSString *myString = myLabel.text;
Now, we are going to want to save that string into NSUserDefaults.
Code:
[[NSUserDefaults standardUserDefaults]setObject:myString forKey:@"myString"];
To access it on startup, we will run this code:
Code:
-(void)viewDidLoad {
NSString *myString = [[NSUserDefaults standardUserDefaults]objectForKey:@"myString"];
}
Now, we can check if the label is equal to something.
Code:
if([myString isEqualToString:@"myEqualStringText"]) {
//Do Stuff
}
I hope that works for you. If you have any questions, just ask!