JAHelia
JAHelia

Reputation: 7932

Tab bar seems to be locked (default settings)

I have created a tabbarcontroller (with its default two view controllers) using interface builder in XCode 4.2.

But, when I run the application, the tab bar seems to be locked and I can't choose the other tab. Why is that?

PS: I haven't changed any property of the tab bar or tabbarcontroller in XCode.

Upvotes: 0

Views: 741

Answers (2)

Simon
Simon

Reputation: 9021

Apologies - assumed because you were using XCode 4.2 that you were using storyboards. Perhaps you could try instantiating a tabbar controller fully in code instead of using IB at all. This is how I usually do it....

// Create the main tabbar controller
tabbarController = [[UITabBarController alloc] init];

// Create the first view controller
MyFirstViewController *v1 = [[MyFirstViewController alloc] initWithNibName:@"MyfirstViewController" bundle:nil];
[v1 setTitle:@"Tab1"];

// Create second view controller
MySecondViewController *v2 = [[MySecondViewController alloc] initWithNibName:@"MySecondViewController" bundle:nil];
[v2 setTitle:@"Tab2"];

// Make an array of controllers for the tabbar
NSArray *tabbarControllerArray = [NSArray arrayWithObjects:v1, v2, nil];

// Set the view controllers used by the tabbar controller
[tabbarController setViewControllers:tabbarControllerArray];

// Release views (retained elsewhere)
[v1 release];
[v2 release];

// Add the controller to the subview
[window addSubview:[tabbarController view]];

// Make key and visible
[self.window makeKeyAndVisible];

Give this way a shot and see how you get on.

Upvotes: 0

Simon
Simon

Reputation: 9021

How did you go about creating the tab bar? Did you have an initial view and then go to the Edit menu -> Embed In -> Tabbar Controller or did you start with nothing and drag in tab bar controller?

Either way, I just created a project with a single view and tried both ways - but the tab still worked. (if you do it by dragging the tab bar controller from the utility pane, you have to also select 'is initial view controller' if you replace the original view created with the project.

EDIT after your comments:

You don't really need to synthesize the tab bar controller in your AppDelegate - storyboarding will take care of this and you can reference it from code without needing generated synthesizers. Just design the layout in storyboard first by dragging in a tabbar controller (this will automatically create the two view controllers by default). Then select the tabbar controller and under the utilities panel, you'll see the 'is initial view controller' checkbox. Make sure it's checked. Then run your project.

Upvotes: 1

Related Questions