UITabBarController question: What controller gets the mesages for a button press?

Discussion in 'iOS Programming' started by SqueegyX, Sep 29, 2008.

  1. SqueegyX macrumors regular

    Joined:
    Mar 24, 2008
    #1
    I have a view with a controller that descends from UITabBarController. In the nib that is loaded by a tab, I set the File's Owner to a custom UIViewController I have and wired some buttons to it.

    When I run it, it works and I see the view. But when I push the button, it crashes with an "unrecognized selector sent to instance". So its not send the linked message where I think it is.

    And I appear to be able to set controller type for each tab in IB, but the list doesn't allow me to choose a custom controller class.

    So I guess my question is, how do I wire up and respond to actions that happen in a nib loaded by a UITabController? Especially since I cant drag connections between nibs :(
     
  2. SqueegyX thread starter macrumors regular

    Joined:
    Mar 24, 2008
    #2
    After reading a bit in the view controller programming guide, I have decided to create the tab bar controller completely via code. However, their example isnt working at all

    Code:
      GalaxyMapController *mapController = [[[GalaxyMapController alloc] init] autorelease];
      LoadoutController *loadoutController = [[[LoadoutController alloc] init] autorelease];
      hyperspaceController.viewControllers = [NSArray arrayWithObjects:mapController, loadoutController, nil];
      NSLog(@"view controllers count: %i", [hyperspaceController.viewControllers count]);
    This prints out "view controllers count: 0". Any clue why they are not being added?
     
  3. SqueegyX thread starter macrumors regular

    Joined:
    Mar 24, 2008
    #3
    Ok, finally figured this out. Turns out the DOCS ARE WRONG.

    This page https://developer.apple.com/iphone/...ngToolbarControllers/chapter_6_section_3.html says to do this:

    Code:
    tabBarController = [[UITabBarController alloc] initWithNibName:nil bundle:nil];
    But the designated initializer is actually supposed to be:

    Code:
    tabBarController = [[UITabBarController alloc] init];
    That change now allows view controllers to be added and displayed.
     

Share This Page