max_
max_

Reputation: 24481

self.tabBarController is NULL

I created a UITabBarController like the following and pushed a navigationController, but I now cannot set the title of tab bar items etc... as the tabbarcontroller is NULL.

Please can you tell me where I am going wrong.

UITabBarController *tabBarController = [[UITabBarController alloc] init];
        LoggedInFeedNavigationController *lvc = [[LoggedInFeedNavigationController alloc] initWithAccount:account];
        [tabBarController setViewControllers:[NSArray arrayWithObject:lvc]];
        [tabBarController setSelectedIndex:0];
        [self presentModalViewController:tabBarController animated:YES];
        [tabBarController release];
        [lvc release];

Upvotes: 3

Views: 2819

Answers (3)

Bryan Norden
Bryan Norden

Reputation: 2537

Joe is completely right. This is also the case for custom segues as well. (Example: SWRevealViewController, etc)

This is what I did to get it to work based on Joe's answer and apples documentation. In YourTabBarViewController.h file add the following:

 @property (nonatomic, retain) UITabBarController * myTabBarController;

Then in YourTabBarViewController.m file in viewDidLoad add the following:

self.myTabBarController = self;
self.myTabBarController.delegate = self;

Upvotes: 0

StuStirling
StuStirling

Reputation: 16191

It looks to me like your releasing your tab bar controller when you haven't finished with it. You want to initialize it once and release it only when your done with it like in the dealloc method.

Upvotes: 0

Joe
Joe

Reputation: 57179

In the documentation for tabBarController I see the following

If no tab bar is present or the receiver is a modal view, this property is nil.

In the comments it says that you are calling self.tabBarController from within the LoggedInFeedNavigationController and I would think it should work properly. But you are displaying the tab bar modally and if the documentation means even if it is inside of UITabBarController as a modal view then that is your problem.

Upvotes: 6

Related Questions