Saving the state

Discussion in 'iOS Development' started by johnmabassa, Jun 4, 2009.

  1. johnmabassa

    johnmabassa Member

    Joined:
    Mar 16, 2009
    Messages:
    87
    Likes Received:
    0
    Hi,
    I needs some help in saving and loading a view's state.

    I have 5 different views and currently user is in 3rd view and if the application terminates due to some reason, I wanted to save the state of that view. I know how to save all the datas in that view using NSUserDefaults but I am not sure how to save that view, so that when the application starts next time, it should show view 3 directly.

    -John
  2. Pelaez-1

    Pelaez-1 New Member

    Joined:
    May 5, 2008
    Messages:
    822
    Likes Received:
    0
    Device:
    iPhone
    Whenever you change view, add this:

    Code:
    [[NSUserDefaults standardUserDefaults] setObject:viewNumber forKey:@"Current View"];
    Then, when the app starts, read the state and go to that view:
    Code:
    //Assuming you saved your "Current View" as an int
    int viewNumber = [[NSUserDefaults] objectForKey:@"Current View"];
    //Also assuming that you have a function that goes to the number of the view specified by an int
    [self goToViewNumber:viewNumber];

Share This Page