问题
I am developing a tabBar application where i am preseting the login page as a modalviewcontroller. Later after logging from the page, i am displaying the TabBar. In one of the Tab i have my LogOut View controller where i want to logout and inturn re-direct the application to the login page. I need to remove all the loaded data and then re-Login with the entered data when i re-Login again. I have searched a lot but not able to find any help on this. Can someone please help me in how to implement this functionality?
回答1:
if you are displaying login view as modelview, then no problem. you can do this again when your user successfully login out. just show the login page by presenting it again.
but my suggestion is that you should make the login as root view of your app and check in app delegate that if user is already logged in then refer to your main page of app else refer to the login page. and at the logout button, jst pop to login view controller. which is root view controller
if([[DataModel sharedDataModel] getValueForKey:USER_SESSION_ID]!=nil) { objLoginController=[[LoginController alloc] initWithNibName:@"LoginController" bundle:nil];
UINavigationController *temp=[[UINavigationController alloc] initWithRootViewController:objLoginController];
self.mNavigationController=temp;
[temp release];
[objLoginController release];
objLoginController = nil;
if(objHomeController==nil)
{
objHomeController=[[HomeController alloc] initWithNibName:@"HomeController" bundle:nil];
}
[self.mNavigationController pushViewController:objHomeController animated:NO];
[objHomeController release];
objHomeController=nil;
[mNavigationController setDelegate:self];
mNavigationController.navigationBar.hidden=TRUE;
[self.view addSubview:mNavigationController.view];
}
else
{
objLoginController=[[LoginController alloc] initWithNibName:@"LoginController" bundle:nil];
UINavigationController *temp=[[UINavigationController alloc] initWithRootViewController:objLoginController];
self.mNavigationController=temp;
[temp release];
[objLoginController release];
objLoginController = nil;
[mNavigationController setDelegate:self];
//mNavigationController.navigationBar.hidden=TRUE;
//[mNavigationController setNavigationBarHidden:NO animated:YES];
[self.view addSubview:self.mNavigationController.view];
}
来源:https://stackoverflow.com/questions/10749716/how-to-logout-from-an-iphone-application-and-re-direct-it-to-login-page