简体   繁体   中英

How to set cutomTabBar to rootViewController?

I m using the library NMBottomTabBarController. (For ref. https://github.com/priankaliz/NMBottomTabBarController )

In AppDelegate.h I've declared property for tabBarController .

@property (nonatomic, strong) NMBottomTabBarController *customTabBarController;

In AppDelegate.m under didFinishLaunchingWithOptions

customTabBarController = (NMBottomTabBarController *)self.window.rootViewController;
customTabBarController.controllers = [NSArray arrayWithObjects:viewController1,viewController2,viewController3,viewController4 nil];
customTabBarController.delegate = self; HomeViewController *controller = [[HomeViewController alloc] initWithNibName:@"HomeViewController" bundle:nil];
    [self.window setRootViewController:controller];

I've tableView in HomeVC. When the row under table is clicked I want customTabBarController to be set as rootViewController . For that I've written

- (void)tableView:(UITableView *)tableView1 didSelectRowAtIndexPath:(NSIndexPath *)indexPath{  
    AppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
    [appDelegate.customTabBarController selectTabAtIndex:indexPath.row];
    [appDelegate.window setRootViewController:appDelegate.customTabBarController.tabBarController];
}

This code is not working. I m not getting the tabBarCotroller screen. What is the correct way?

I think your problem is with this line

[appDelegate.window setRootViewController:appDelegate.customTabBarController.tabBarController];

Try by changing it like this:

[appDelegate.window setRootViewController:appDelegate.customTabBarController];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM