TabBarController和NavigationController

时间:2013-06-24 13:21:32

标签: ios objective-c uinavigationcontroller uitabbarcontroller uitabbaritem

我正在创建一个应用程序,但我仍然是初学者,我正在尝试习惯RootViewController以及如何设置它。

一开始我的应用程序启动,我希望有一个View不在我的tabBarController中(它被设置为我的rootViewController)。

我想问的是,如果没有它位于tabBarController的项目列表中,我可以首先在UITabBarController之外启动另一个视图吗?

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.

    FacebookFeedViewController *facebookClass = [[FacebookFeedViewController alloc] initWithNibName:@"FacebookFeedViewController" bundle:nil];

    TwitterFeedViewController *twitterClass = [[TwitterFeedViewController alloc] initWithNibName:@"TwitterFeedViewController" bundle:nil];
    LinkedInFeedViewController *linkClass = [[LinkedInFeedViewController alloc] initWithNibName:@"LinkedInFeedViewController" bundle:nil];
    FTLFullFeedViewController *masterClass = [[FTLFullFeedViewController alloc] initWithNibName:@"FTLFullFeedViewController" bundle:nil];

    ///   tab button title

    facebookClass.title = @"Facebook";
    twitterClass.title = @"Twitter";
    linkClass.title=@"LinkedIn";
    masterClass.title=@"FTL";

    // tab button Images
    facebookClass.tabBarItem.image = [UIImage imageNamed:@"facebook_32"];
    twitterClass.tabBarItem.image = [UIImage imageNamed:@"twitter_32"];

    WelcomeViewController *welcomeClass= [[WelcomeViewController alloc] initWithNibName:@"WelcomeViewController" bundle:nil];

    navController = [[ UINavigationController alloc] initWithRootViewController:welcomeClass];

    UINavigationController *navController2 = [[UINavigationController alloc] initWithRootViewController:facebookClass];
    UINavigationController *navController3 = [[UINavigationController alloc] initWithRootViewController:twitterClass];
    UINavigationController *navController4 = [[UINavigationController alloc] initWithRootViewController:linkClass];
    UINavigationController *navController5 = [[UINavigationController alloc] initWithRootViewController:masterClass];

    self.tabBarController = [[UITabBarController alloc] init];
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:navController,navController5,navController2,navController3,navController4,nil];
    self.window.rootViewController = self.tabBarController;
    [self.window makeKeyAndVisible];

    return YES;
}

2 个答案:

答案 0 :(得分:0)

是的!你当然可以。

[self.view addsubview:yourTabbar.view];

希望这会对你有所帮助。

答案 1 :(得分:0)

我知道您已经选择了一个答案,但所有正在做的就是在现有视图的顶部推送UITabBar视图,而不是创建新的UITabBarController视图。基于我们的简短对话(最新的XCode,没有StoryBoards,使用XIB),您将要创建一个xib作为UITabBarController,然后将其推入视图...

View *view = [[View alloc] initWithNibName:@"myUITabBarXIB" bundle:nil];
view.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController: view animated:YES];

当您执行所需的操作时,这将显示您的XIB文件,但不会显示在现有视图控制器之上。