Reputation: 21
I use the custom UINavigationController
as a rootViewController. The UINavigationController's
first viewController is a UITabBarController
. Each UITabBarController
is a custom UINavigationConller
.When the tabBarController
is shown, I hide the rootViewController's
navigationBar
.
Init the
UITabbarController
+(RDVTabBarController *)tabBarControllertWithIndex:(NSUInteger)index
{
UIViewController *goodsHomeController = [[ESGoodsHomeViewController alloc] initWithNibName:nil bundle:nil];
UINavigationController *goodsHomeNavi = [[ESNavigationController alloc]
initWithRootViewController:goodsHomeController];
........
ESTabBarController *tabBarController = [[ESTabBarController alloc] init]; //对status bar 能定制
[tabBarController setViewControllers:@[goodsHomeNavi,categoryNavi,shoppingCarNavi,userCenterNavi]];
return tabBarController;
}
Set it to a
navigationController
self.tabController = [UIHelper tabBarControllertWithIndex:0];
self.tableController.delegate = self;
UINavigationController *tabBarNavigation = [UIHelper navigationControllerViewController:self.tableController];
tabBarNavigation.navigationBarHidden = TRUE;
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
self.window.rootViewController = tabBarNavigation;
In the baseViewController ,I customise the back item in the navigationBar
- (void)setCustomNavigationBackButton
{
UIImage *backBtn = [UIImage imageNamed:@"bar_back"];
UIImage *backDownBtn = [UIImage imageNamed:@"bar_back_down"];
backBtn = [backBtn imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
backDownBtn = [backDownBtn imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
self.navigationItem.backBarButtonItem.title=@"";
self.navigationController.navigationBar.backIndicatorImage = backBtn;
self.navigationController.navigationBar.backIndicatorTransitionMaskImage = backBtn;
}
In some cases, I change the
viewControllers
of anavigationController
when I push aviewController
after the push animation is finished. I use a navigationController+block
- (void)popToViewController:(UIViewController *)viewController animated:(BOOL)animated onCompletion:(void(^)(void))completion
{
[CATransaction begin];
[CATransaction setCompletionBlock:completion];
[self popToViewController:viewController animated:animated];
[CATransaction commit];
}
After finished the block is executed
[UIHelper viewController:self pushViewController:orderDetail completion:^{
NSMutableArray *afterController = [NSMutableArray array]; //将本页面删除
NSArray *viewController = self.navigationController.viewControllers;
[viewController enumerateObjectsUsingBlock:^(UIViewController *obj, NSUInteger idx, BOOL *stop) {
if (![obj isKindOfClass:[ESPurchaseViewController class]]) {
[afterController addObject:obj];
}
}];
self.navigationController.viewControllers = afterController;
}];
In some push, when I come from the UITabBarController
push to a secondViewController
, I hide navigationBar
and show the root navigationBar
.
+(void)tabController:(UIViewController *)tabController pushSubController:(UIViewController *)subViewController
{
[tabController.rdv_tabBarController.navigationController pushViewController:subViewController animated:YES];
tabController.rdv_tabBarController.navigationController.navigationBarHidden = FALSE;
}
I can not find the reason why the navigation can not pop. That does not always happen.
Any wrong basic knowledge of iOS about the UINavigationContller
,UITabBarController
,UIViewController
for me to know?
Thank you!
Upvotes: 2
Views: 217
Reputation: 2328
if i think your need is First MainNavigationViewController then tabbar Controller with it and each tab bar's view controller is also having its own nvaigation controller then it will work fine..
listViewController = [[CBListViewController alloc] initWithStyle:UITableViewStylePlain];
bookmarkController = [[CBBookmarksViewController alloc] initWithStyle:UITableViewStylePlain];
settingsController = [[CBActivityViewController alloc] init ];
searchController = [[CBSearchViewController alloc] initWithNibName:@"CBSearchViewController" bundle:nil];
nearbyController = [[CBViewOnMapViewController alloc] init ];
UINavigationController *bNavigationController = [[UINavigationController alloc] initWithRootViewController:bookmarkController];
self.navigationControllerForBookmark = bNavigationController;
UITabBarItem *tab2=[[UITabBarItem alloc]init];
tab2.image = [[UIImage imageNamed:@"bookmark.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
tab2.selectedImage = [[UIImage imageNamed:@"bookmark_active.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
tab2.imageInsets = UIEdgeInsetsMake(5, 0, -5, 0);
navigationControllerForBookmark.tabBarItem = tab2;
UINavigationController *cNavigationController = [[UINavigationController alloc] initWithRootViewController:settingsController];
self.navigationControllerForSettings = cNavigationController;
UITabBarItem *tab3=[[UITabBarItem alloc]init];
tab3.image = [[UIImage imageNamed:@"activites.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
tab3.selectedImage = [[UIImage imageNamed:@"activites_active.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
tab3.imageInsets = UIEdgeInsetsMake(5, 0, -5, 0);
navigationControllerForSettings.tabBarItem = tab3;
UINavigationController *dNavigationController = [[UINavigationController alloc] initWithRootViewController:searchController];
self.navigationControllerForSearch = dNavigationController;
UITabBarItem *tab4=[[UITabBarItem alloc]init];
tab4.image = [[UIImage imageNamed:@"Search.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
tab4.selectedImage = [[UIImage imageNamed:@"Search_active.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
self.navigationController.tabBarItem = tab4;
tab4.imageInsets=UIEdgeInsetsMake(5, 0, -5, 0);
navigationControllerForSearch.tabBarItem=tab4;
UINavigationController *eNavigationController = [[UINavigationController alloc] initWithRootViewController:nearbyController];
self.navigationControllerForNearby = eNavigationController;
UITabBarItem *tab5=[[UITabBarItem alloc]init];
tab5.image = [[UIImage imageNamed:@"nearby.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
tab5.selectedImage = [[UIImage imageNamed:@"nearby_active.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
self.navigationController.tabBarItem = tab5;
tab5.imageInsets = UIEdgeInsetsMake(5, 0, -5, 0);
navigationControllerForNearby.tabBarItem = tab5;
[navigationControllerForNearby.navigationBar setBackgroundImage:[UIImage imageNamed:@"headerBar"] forBarMetrics:UIBarMetricsDefault];
UINavigationController *aNavigationController = [[UINavigationController alloc] initWithRootViewController:listViewController];
self.navigationController = aNavigationController;
UITabBarItem *tab1=[[UITabBarItem alloc]init];
tab1.image = [[UIImage imageNamed:@"review.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
tab1.selectedImage = [[UIImage imageNamed:@"review_active.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
tab1.imageInsets = UIEdgeInsetsMake(5, 0, -5, 0);
navigationController.tabBarItem = tab1;
[[UITabBar appearance] setBarTintColor:GRAY_COLOR];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:navigationController, navigationControllerForNearby, navigationControllerForSearch, navigationControllerForBookmark, navigationControllerForSettings, nil];
self.window.rootViewController = self.tabBarController;
check if this solves your problem sir.
Upvotes: 1