Reputation: 37
This code works perfectly to switch view controllers,except the tab bar controller disappears.
Now I try many different variations of this code
[self presentViewController:homeNavigationController animated:NO completion:nil];
But none of them seems to work properly. The push controller just freezes the view in place. Any tips on what to do?
- (void)_tabBarItemClicked:(id)item {
assert([item isKindOfClass:[UIButton class]]);
NSInteger selectedIndex = ((UIButton *)item).tag;
[self setSelectedIndex:selectedIndex];
[self _setSelectedItemAtIndex:selectedIndex];
NSDictionary *userInfo = @{@"index": [NSNumber numberWithInt:selectedIndex]};
[[NSNotificationCenter defaultCenter] postNotificationName:@"tabBarDidSelectItem" object:nil userInfo:userInfo];
if (selectedIndex ==2) {
HomeViewController *homeViewController = [[HomeViewController alloc] initWithNibName:nil bundle:nil];
UINavigationController *homeNavigationController = [[UINavigationController alloc] initWithRootViewController:homeViewController];
[self presentViewController:homeNavigationController animated:NO completion:nil];
}}
Upvotes: 0
Views: 1190
Reputation: 2451
I solved this problem by:
1) Define YourTabBarController object in AppDelegate
2) And presentViewController from YourTabBarController's object instead of 'self' like
[appDelegateObj.yourTabBarObj presentViewController:homeNavigationController animated:NO completion:nil];];
Make sure your Appdelegate object is initialized.
Upvotes: 1
Reputation: 104082
You're presenting homeNavigationController modally -- what you're seeing is the normal behavior of a modal view controller, that is, they take over the whole screen including the tab bar. If you want to see the tab bar, then don't use a modal presentation.
Upvotes: 1