tags:

views:

214

answers:

2

hi iam going to create an application and my app remember last user action ,, it means user find himself in the same page as he was last time he ran the application .here is my codes but doesn't work ! what is my problem ?

.h

#define HOME_VIEW 0
#define VIEW1 1
#define VIEW2 2


.m    
    - (void)viewDidLoad {
        [super viewDidLoad];

    // Set the name of the view
    [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithInt:VIEW1] forKey:@"lastView"];

}

App Delegate :

- (void)applicationDidFinishLaunching:(UIApplication *)application {
   // Retrieve the last view name
   NSInteger constantView = [[NSUserDefaults standardUserDefaults] integerForKey:@"lastView"];

   switch(constantView) {
      case HOME_VIEW : //load your UIViewController
          break;
      case VIEW1 : // load your VIEW1
          break;
      //...
   }
}
A: 

You have quite a bit of code missing but try moving

 [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithInt:VIEW1] forKey:@"lastView"];

To

- (void) viewDidAppear

instead of viewDidLoad

Ron Srebro
sorry but still doesn't work ! sorry iam new to iphone sdk how can define forKey:@"lastView"]
Momeks
Please add NSLog(@"%d",constantView) before the switch statement and report the results so would have a clue where the problem is.
Ron Srebro
A: 

Check out SpringBack for application state saving.

catlan