tags:

views:

76

answers:

2

Hi All,

Fairly new to iPhone app development, so this might be really obvious (if so, apologies in advance!)

I'm building an app which has a tab bar. However, when the app first runs and 'launch screen' is shown with 3 UIButtons - each of these buttons points at a view of one of the tabs. What I need to do is:

Close the existing view Open the selected view Set the highlighted tab accordingly

This sounds like it should be quite easy, but a few hours of Googling has found nothing!

Thanks for your help, Kev

Additional:
Sorry - I am using a tabBarController... But instead of immediately launching the tab bar views I'm using the code below to launch the home menu instead.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    homeViewController *splashView = [[homeViewController alloc] initWithNibName:@"homeView" bundle:nil];
    [window addSubview:splashView.view];


//  [window addSubview:tabBarController.view];
    [window makeKeyAndVisible];

    return YES;
}

On the home menu there are UIButtons which need to link to individual tabs... Hope this clarifies...

Cheers!

A: 

Hi kevstar76, it's a bit hard to fully understand your question, but it sounds like you should be using UITabBarController instead of the stand-alone view UITabbar. This is essential reading! Good luck

eliego
Sorry - I should have been clearer - I'm using a UITabBarController but am loading another screen first - more info added above.Thanks for your help so far!
kevster76
+1  A: 

Oh. Then it gets a bit more complex. What you want to do is basically this:

  1. Add a method to your AppDelegate - (void)showTabBarWithSelectedTab:(NSUInteger)tabIndex. In this method, use tabBarController.selectedIndex to select the correct index, then remove homeViewController's view from the window and add tabBarController's view instead.
  2. In homeViewController, have actions for the buttons that calls the newly created AppDelegate method with the correct tab index.

Generally I would say that this adds a bit too much logic to the AppDelegate. Ideally you'd implement this in a new view controller, surrounding and managing both homeViewController and tabBarController. However, having a UITabbarController inside of another view controller isn't officially supported - although you can get it to work anyway.

eliego
Many thanks eliego! I'm almost there! It's all loading now, but when I 'build and run' it's presenting a warning: '-showTabBarWithSelectedTab:' not found in protocol(s)'Here's the code: #import "homeViewController.h" #import "SilverDoorAppDelegate.h" #define myAppDelegate [[UIApplication sharedApplication] delegate] @implementation homeViewController -(IBAction) goSearch:(id)sender { [myAppDelegate showTabBarWithSelectedTab:0]; }Many thanks - really appreciate your help!
kevster76
Change #define myAppDelegate [[UIApplication sharedApplication] delegate] to #define myAppDelegate ((NameOfYourAppDelegateClass *)[[UIApplication sharedApplication] delegate]). Because [[UIApplication sharedApplication] delegate] is declared to return any object that implements the ApplicationDelegate protoco, when adding functionality not in this protocol you have to explicitly cast the object to your application delegate class. Feel free to accept the answer when you get it to work - it's still possible to add comments and answers afterwards. And - you're welcome ;)
eliego
Perfect - many thanks!!!
kevster76