views:

59

answers:

1

Hi guys!,

i need some help:

i have several views (view xib): login, sign up, settings, and so on.

i have created a project, added a tab controller and the tabs are working fine.

The problem is that: we have 2 sign up 'ways' and my boss want them in two different tabs. The code is almost equal, so my idea is:

instead of having 2 different views with copied & pasted code, i would like to create a general sign up view and just 'fire' the signUp_method1 if the user presses the first tab, also if the user presses the second tab i will fire the signUp_method2. the question is how should i do this?.

also, i'm worried that i will not be able to customize the view depending of the action: i have to show 2 different fields and labels according to the sign up way. i have been looking for some way, i read about viewDidLoad and actually i'm using it for initialization but that does not solve the problem.

Perhaps i should not use tab controller, so, if you have suggestions i'm happy to read them.

Thanks for reading.

A: 

Use the UITabBar delegate methods. You need to make sure the view that the tab bar is in implements the "UITabBarDelegate" in the class header.

This method might do the trick:

-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
 // You can put logic in here to check on what item was pressed and fire the different methods depending on what you put.  
    if ([[item title] isEqualToString:@"Libraries"]) {
  NSLog(@"Pressed on libraries tab!!");
 } else if ([[item title] isEqualToString:@"Search"]) {
     NSLog(@"Pressed on search tab!!");
  }
}

You can find a nice tutorial here: http://www.iphonesdkarticles.com/2008/07/tab-bar-controller-tutorial.html

As long as you have your components linked up in IB to your controller properly, you should be able to programmatically manipulate them as needed.

Geoff Baum