iphone - How to manage state in ios objective c -


i’m new in ios development. question is, i’ve 2 view controllers.

viewcontroller - viewcontroller - b

now, if killed app viewcontroller - , relaunch app. app must open viewcontroller - a. , if killed app viewcontroller - b , relaunch app. app must open viewcontroller - b.

can me, i’ve done rnd can not find proper solution.

thanks

  1. make shareddelegate in appdelegate.m file

    +(appdelegate *)shareddelegate {

    return (appdelegate *) [uiapplication sharedapplication].delegate;

    }

  2. in appdelgate.h

    +(appdelegate *)shareddelegate; @property (nonatomic,strong) nsstring *currentviewcontoller;

  3. when push anycontoller set appdelegates currentviewcontoller new vc

viewcontroller *vc=[[viewcontroller alloc]init]; [self.navigationcontroller pushviewcontroller:vc animated:yes];

[appdelegate shareddelegate].currentviewcontoller=nsstringfromclass([viewcontroller class]);

  1. now when app terminated

    • (void)applicationwillterminate:(uiapplication *)application {

    // called when application terminate. save data if appropriate. see applicationdidenterbackground:.

[[nsuserdefaults standarduserdefaults]setobject:[appdelegate shareddelegate].currentviewcontoller forkey:@"cuurentvc"];

} 

5 when app launched first time check previous controller when app terminated

- (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions {      nsstring *string=[[nsuserdefaults standarduserdefaults] valueforkey:@"cuurentvc"]; 

and push class

    uiviewcontroller *object = [[nsclassfromstring(string) alloc] init...];  } 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -