Ahmad Kayyali
Ahmad Kayyali

Reputation: 8243

Add Logout Button To be visible everywhere in an iPhone application

I am building an iPhone application that requires the user to enter his credentials 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?

Upvotes: 0

Views: 1438

Answers (3)

Desdenova
Desdenova

Reputation: 5378

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
    }
}

Upvotes: 1

Nils Munch
Nils Munch

Reputation: 8845

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];

Upvotes: 1

Legolas
Legolas

Reputation: 12325

Just a guess. Did you try using your Navigation Controller as your root Controller ? You can use the rightBarButtonItem for Logging out.

Upvotes: 0

Related Questions