Custom UITabBarController and UINavigationController

后端 未结 4 522
心在旅途
心在旅途 2020-12-22 05:04

I\'m developing an app for iOS5 and up and I don\'t use storyboards or IB. I\'m creating a custom UITabBarController and in my AppDelegate I\'m put

4条回答
  •  既然无缘
    2020-12-22 05:30

    Yes, you can. Try something like this code in yourUITabBarController.m:

    - (void)viewDidLoad
    {
        [super viewDidLoad];
            
        NSMutableArray* sectionViewControllers = nil;
        NSArray* controllers = [self controllers];
        UIViewController* controller = nil;
        
        for (controller in controllers)
        {
            if (sectionViewControllers == nil)
                sectionViewControllers = [NSMutableArray arrayWithCapacity:0];
            
            UINavigationController* navigationController = [[UINavigationController allocWithZone:[self zone]] initWithRootViewController:controller];
            
            navigationController.navigationBarHidden = YES;
            
            [sectionViewControllers addObject:navigationController];
            [navigationController release];
        }
        
        self.viewControllers = sectionViewControllers;
    }
    
    - (NSArray*)controllers
    {
        if (!_controllers)
            _controllers = [NSArray arrayWithObjects:[self tabController1], [self tabController2], nil];
        return _controllers;
    }
    

    and this in you AppDelegate.m:

    self.window.rootViewController = self.yourUITabBarController;
    

提交回复
热议问题