1

Say for example if I have two buttons one for apples and one for orange, and I select apples and takes me to the apples screen. How can I make it for now on every time I run the app it will go to the apples screen?

1
  • 1
    Did you do any research? Did you see the existing questions on SO? Commented Dec 4, 2012 at 14:03

4 Answers 4

3

in viewDidLoad

if([[NSUserDefaults standardUserDefaults] objectForKey:@"fruit"] != nil) { if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"fruit"]isEqualToString:@"apple"]) { [self.navigationController pushViewController:appleVC animated:NO]; } else{ [self.navigationController pushViewController:orangeVC animated:NO]; } } 

and on Button Methods

on Apple button

[[NSUserDefaults standardUserDefaults] setObject:@"apple" forKey:@"fruit"]; 

on Orange button

[[NSUserDefaults standardUserDefaults] setObject:@"orange" forKey:@"fruit"]; 
Sign up to request clarification or add additional context in comments.

Comments

2

You can store information like this using NSUserDefaults.

You'd store a boolean bAppleSelected like this:

NSUserDefaults * standardUserDefaults = [NSUserDefaults standardUserDefaults]; [standardUserDefaults setBool:bAppleSelected forKey=@"appleSelected"]; 

You can read it by accessing the default userDefaults:

BOOL bApple = [standardUserDefaults boolForKey=@"appleSelected"]; 

Comments

0

On your app delegate you must have some method that instantiates the very first controller and displays it in a window. You can just create an "apples controller" and push it there

Comments

0

You can use NSUserdefaults here,

NSString* fruit=@"apple"; [[NSUserDefaults standardUserDefaults]setObject:fruit forKey:@"controllerName"]; [[NSUserDefaults standardUserDefaults]synchronize]; 

and insted of the name string of your firstview controller in appdelegate file use the above NSUserDefaults.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.