PDA

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




SqueegyX
Sep 29, 2008, 10:34 PM
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 :(



SqueegyX
Sep 30, 2008, 12:05 PM
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

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?

SqueegyX
Sep 30, 2008, 01:07 PM
Ok, finally figured this out. Turns out the DOCS ARE WRONG.

This page https://developer.apple.com/iphone/library/featuredarticles/ViewControllerPGforiPhoneOS/UsingToolbarControllers/chapter_6_section_3.html says to do this:

tabBarController = [[UITabBarController alloc] initWithNibName:nil bundle:nil];

But the designated initializer is actually supposed to be:

tabBarController = [[UITabBarController alloc] init];

That change now allows view controllers to be added and displayed.