0

My app currently has a UINavigationController and I'd like to push a mainTabBarController(subclassed UITabBarController) at some point when finished login process. I am trying to create it on Interface Builder (as opposed to programmatically).

My issue is that mainTabBarController seems to be pushed on the UINavigationController so I can see all the tab bars at the bottom, however, I don't see any view elements on the screen which there should be. I see only black screen and tab bars.

I doublechecked if there are view elements such as labels and buttons on the right place on each viewcontrollers that are embedded in mainTabBarController.

I followed this tutorial and read this article carefully but still can't find what's wrong.

MainTabBarController *mainTabBarVC = [MainTabBarController new];

// Create child VCs for tabBarController
self.feedVC = [FeedViewController new];  
self.chatVC = [ChatViewController new];
self.friendsVC = [FriendsViewController new];
self.meVC = [MeViewController new];

self.feedVC.tabBarItem.title = @"Feed";
self.chatVC.tabBarItem.title = @"Chat";
self.friendsVC.tabBarItem.title = @"Friends";
self.meVC.tabBarItem.title = @"Me";

mainTabBarVC.viewControllers = @[self.feedVC, self.chatVC, self.friendsVC, self.meVC];

[self.navigationController pushViewController:mainTabBarVC animated:YES];

EDIT : I solved this issue with below code. Frankly, I still don't get it why I couldn't with above code. Hope this help somebody.

self.feedVC = [self.storyboard instantiateViewControllerWithIdentifier:@"FeedVC"];
self.chatVC = [self.storyboard instantiateViewControllerWithIdentifier:@"ChatVC"];
self.friendsVC = [self.storyboard instantiateViewControllerWithIdentifier:@"FriendsVC"];
self.meVC = [self.storyboard instantiateViewControllerWithIdentifier:@"MeVC"];

self.feedVC.tabBarItem.title = @"Feed";
self.chatVC.tabBarItem.title = @"Chat";
self.friendsVC.tabBarItem.title = @"Friends";
self.meVC.tabBarItem.title = @"Me";

mainTabBarVC.viewControllers = @[self.feedVC, self.chatVC, self.friendsVC, self.meVC];

[self.navigationController pushViewController:mainTabBarVC animated:YES];

1 Answer 1

1

To achieve what you want, I think it should look something like this:

//create a UITabBarController object
UITabBarController *tabBarController=[[UITabBarController alloc]init];

// Create child VCs for tabBarController
FeedViewController *feedVC=[[FeedViewController alloc]initWithNibName:@"feedVC" bundle:nil];
ChatViewController *chatVC=[[ChatViewController alloc]initWithNibName:@"chatVC" bundle:nil];

//adding view controllers to your tabBarController bundling them in an array
tabBarController.viewControllers=[NSArray arrayWithObjects: feedVC,chatVC, nil];

//navigating to the UITabBarController that you created
[self.navigationController pushViewController:tabBarController animated:YES];
Sign up to request clarification or add additional context in comments.

3 Comments

How can I set a nibname on each VC with IB? And do I really need to do it? Thanks anyways~
Before going further I'd like to know if you still have your original issue in your question.
Yes I still have the issue

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.