0

I have created an application that have 9 screen and I have added tabbar in it which contain 4 baritem. Now I have two problems -

1 => My last baritem is logout button, I don't want to display view controller for it, simply when user click this button then alertview should pop up and ask for logout and if user says yes then it will logout.

2=> How to display tabbar in that view controller that does not added in tabbar, because I have 9 screen and only 4 screen display in tabbar.

UPDATE

I said that I have 9 view controller in my app

like...

firstViewController
secondViewController
thirdViewController
fourViewController
|
|
ninthViewController

But my tabbar have only four view controller in baritem which are -

firstViewController
secondViewController
thirdViewController
fourViewController

Now, my other view controller does not display tabbar.

Nayan
  • 3,014
  • 2
  • 17
  • 33

2 Answers2

1

I dont know this is right way or not but you can do it like this...

first read this question that show how to display login and come back to home.

Now add this code in didFinishLaunchingWithOptions method

UIViewController * logoutVC =[[UIViewController alloc] init];

NSArray *viewControllersArray = [[NSArray alloc] initWithObjects:firstView, secondView, thirdView,logoutVC, nil];

self.tabController = [[UITabBarController alloc] init];
[self.tabController setViewControllers:viewControllersArray animated:YES];
[self.window addSubview:self.tabController.view];

And implement this delegate method of tabbar

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
    //select the index where your logout button is
    if ([tabBarController selectedIndex] == 3) {
        NSLog(@"logout");
        self.tabController.selectedViewController = fistView;  //firstview is your home screen
        //LOGOUT
        LoginViewController * vc = [[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:nil];
        vc.delegate = self;
        [self.tabController presentModalViewController:vc animated:NO];
    }
}
Community
  • 1
  • 1
Dilip Manek
  • 9,095
  • 5
  • 44
  • 56
  • this is really nice,but it will solve only first question.but still good answer. –  Jan 16 '13 at 16:23
0

Your first question:

Don't do this, it's an abuse of tab bar controller. Each item on the tab bar controller should be a different view in your app, not an action. Find an appropriate place for a logout action button.

Your second question:

There are several ways to show a view controller that isn't one of the main VCs for the tab bar controller. It could be reached by:

  • being shown as a modal screen

  • as a popover

Update

To show a 'secondary' view controller that isn't a main VC of the tab bar, but still have the tab bar visible, you can present that secondary VC as a sub-viewcontroller of a main tab bar VC. In other words, present the view of your secondary VC as a subview of a main VC view.

occulus
  • 16,959
  • 6
  • 53
  • 76
  • I guess he means that in one of the views that is independent from tabbar he still wants to display the tabbar. – SpaceDust__ Jan 16 '13 at 15:56
  • But than i have to make button in every view controller.right. –  Jan 16 '13 at 15:59
  • I tried to use secondary VC as subview of first VC but that stops my application when i touch the textview in my secondary VC... –  Jan 17 '13 at 05:15