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
make shareddelegate in appdelegate.m file
+(appdelegate *)shareddelegate {
return (appdelegate *) [uiapplication sharedapplication].delegate;
}
in appdelgate.h
+(appdelegate *)shareddelegate; @property (nonatomic,strong) nsstring *currentviewcontoller;
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]);
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
Post a Comment