views:

36

answers:

1

Hi,

I have an iPhone application that is setup as follows:

  • UITabBarController
  • CustomViewControllerLogin (UIViewController)
  • UINavigationController
    • CustomViewController1 (UIViewController)
    • CustomViewController2 (UIViewController)
  • CustomViewControllerLogout (UIViewController)

How do I switch to CustomViewController1, when the user clicks the Login button on CustomViewControllerLogin?

I also, need to "hide" CustomViewControllerLogin and "show" CustomViewControllerLogout?

Thanks in advance!!! Jason

A: 

Well, your approach doesn't seem to be the most fortunate one to me.

What you could do is to replace the UITabBarController with a UINavigationController and go with the following approach:

  • present your CustomViewControllerLogin modally. You can use something like this:

[self.navigationController presentModalViewController:instanceOf CustomViewControllerLogin animated:YES];

  • set the rootViewController in the navigationController to be your CustomViewController1

  • in your CustomViewControllerLogin, once the login is done successfully, dismiss the CustomViewControllerLogin using the following:

[self dismissModalViewControllerAnimated:YES]

  • when this gets executed, your CustomViewController1 will be displayed. Do your app logic here and have a "Logout" button. You could put it on the navigation bar, on the right side for example.

  • when the user taps on this logout button, you do the same as you did for the login:

[self.navigationController presentModalViewController:instanceOf CustomViewControllerLogout animated:YES];

I have seen a lot of apps where the UITabBarController is abused for purposes that it wasn't intended for. See for example this article.

Stelian Iancu
Hi Stelian,First thanks for your time. It is appreciated!!!I agree that TabBarController can be abused, but I do have separate information types that I would like to organize with the TabBarController.I was hoping that like in Microsoft Access' Tab Control you can say something like: tab1.visible = False.Any idea how to go about this?P.S., you gave me a lot of food for thought about re-organizing to eliminate the TabBarController, but I want to continue to understand this before changing direction.Jason
JasonBub
Hi Stelian, I just wanted to let you know that your suggestion really helped me to think about the organization of my application differently. I have incorporated Model views now to handle gathering the credentials of the user, which lead me to under delegation (through the use of @protocol, which is really cool). Thanks!
JasonBub
Hi Jason, glad to hear that. You're welcome!
Stelian Iancu