objective c - Logging off ios app and returning to RootViewController -
objective c - Logging off ios app and returning to RootViewController -
i created rootviewcontroller in app delegate so:
- (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions { self.window = [[uiwindow alloc] initwithframe:[[uiscreen mainscreen] bounds]]; startviewcontroller *viewcontroller = [[startviewcontroller alloc] init]; startnavigationcontroller *navigationcontroller=[[startnavigationcontroller alloc] initwithrootviewcontroller:viewcontroller]; self.window.rootviewcontroller = navigationcontroller; [self.window makekeyandvisible]; }
when nail logout button, want send user rootview controller:
- (ibaction) logoutbuttonpressed:(uibutton *)sender { [users logout]; [self.navigationcontroller poptorootviewcontrolleranimated:yes]; }
this works fine when run on iphone 4s (testing iphone 6 when arrives), if leave user logged in more day , click logout button, screen slides black.
why root view controller not calling startviewcontroller after 24 hours or so?
i trying set answer, guess should work you. first check startviewcontroller
whether exist in navigationcontroller stack or, not. per stack startviewcontroller
should first controller added in navigationcontroller
.
startviewcontroller *logincontroller=[self.navigationcontroller.viewcontrollers objectatindex:0]; if(logincontroller){ [self.navigationcontroller poptoviewcontroller:logincontroller animated:yes]; }else{ nsmutablearray *controllers=[[nsmutablearray alloc] init]; logincontroller=[[startviewcontroller alloc] initwithnibname:@"startviewcontroller" bundle:nil]; [controllers addobject:logincontroller]; [controllers addobjectsfromarray:self.navigationcontroller.viewcontrollers]; self.navigationcontroller.viewcontrollers=[[nsarray alloc] initwitharray:controllers]; [self.navigationcontroller poptorootviewcontrolleranimated:yes]; }
i think should work.
cheers.
ios objective-c parse.com uinavigationcontroller rootview
Comments
Post a Comment