Add Logout Button To be visible everywhere in an iPhone application
I am building an iPhone application that requires the user to enter his credenti开发者_开发百科als in order to use the application and can sign out in any moment.
I have used UITabBarController
to navigate through my views, now I need to add a Logout button in a way that it is available/visible all the time.
Can anybody suggest a solution or best practice for this case?
Can you spare a tab bar item for that? It seems like the most clean way. Then you can use
tabBarController:didSelectViewController:
method of the UITabBarControllerDelegate
.
something like this (assuming that the logout tab is the 5th tab)
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController { if ([tabBarController selectedIndex] == 4) { //LOGOUT } }
The best way would be to use the Right Button Position for it.
UIBarButtonItem *saveButton = [[UIBarButtonItem alloc]
initWithTitle:@"Logout"
style:UIBarButtonItemStylePlain
target:self
action:@selector(yourLogoutSelector)];
self.navigationItem.rightBarButtonItem = saveButton;
[saveButton release];
Just a guess. Did you try using your Navigation Controller as your root Controller ? You can use the rightBarButtonItem for Logging out.
精彩评论