将UiViewController添加到Root View Controller

时间:2016-04-12 18:15:42

标签: ios objective-c

如何将侧边栏添加到self.viewcontroller以初始化内容。 self.viewController是一个rootViewController

- (void)setupViewControllers {
    UIViewController *firstViewController = [[BdbHomeListViewController alloc] init];
    UIViewController *firstNavigationController = [[UINavigationController alloc]
                                                   initWithRootViewController:firstViewController];

    UIViewController *secondViewController = [[BdbExpiredListViewController alloc] init];
    UIViewController *secondNavigationController = [[UINavigationController alloc]
                                                    initWithRootViewController:secondViewController];

    UIViewController *thirdViewController = [[BdbHistoryListViewController alloc] init];
    UIViewController *thirdNavigationController = [[UINavigationController alloc]
                                                   initWithRootViewController:thirdViewController];

    UIViewController *forthViewController = [[BdbChatRoomListViewController alloc] init];
    UIViewController *forthNavigationController = [[UINavigationController alloc]
                                                   initWithRootViewController:forthViewController];

    UIViewController *fithViewController = [[RightViewController alloc]init];
    UIViewController *fithNavigationController = [[UINavigationController alloc]
                                                   initWithRootViewController:fithViewController];

    RDVTabBarController *tabBarController = [[RDVTabBarController alloc] init];
    [tabBarController setViewControllers:@[firstNavigationController, secondNavigationController,
                                           thirdNavigationController,forthNavigationController,fithNavigationController]];

    TheSidebarController *sidebar = [[TheSidebarController alloc] initWithContentViewController:self.viewController rightSidebarViewController:fithNavigationController];
    self.viewController = tabBarController;

    [self customizeTabBarForController:tabBarController];
}

1 个答案:

答案 0 :(得分:0)

我认为你应该这样做:

TheSidebarController *sidebar = [[TheSidebarController alloc] initWithContentViewController:tabBarController rightSidebarViewController:fithNavigationController];
self.window.rootViewController= sidebar;
[self.window makeKeyAndVisible];

你也不需要这个:

self.viewController = tabBarController;