Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/115.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在ios7中显示所有选项卡栏标题_Ios_Objective C_Uiviewcontroller_Uitabbarcontroller - Fatal编程技术网

如何在ios7中显示所有选项卡栏标题

如何在ios7中显示所有选项卡栏标题,ios,objective-c,uiviewcontroller,uitabbarcontroller,Ios,Objective C,Uiviewcontroller,Uitabbarcontroller,基本上,当我运行我的应用程序时,我无法显示所有选项卡栏项目,只显示第一个视图控制器: 我必须单击选项卡才能显示其项目: 这是我在Appdelegate.m中的代码: - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Initialize window self.window = [[UIWindow

基本上,当我运行我的应用程序时,我无法显示所有选项卡栏项目,只显示第一个视图控制器:

我必须单击选项卡才能显示其项目:

这是我在Appdelegate.m中的代码:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Initialize window
    self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];

    // Set background colors for both NavBar and TabBar
    [[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:0.157 green:0.718 blue:0.553 alpha:1]];
    [[UITabBar appearance] setBarTintColor:[UIColor colorWithRed:0.141 green:0.216 blue:0.263 alpha:1]];

    // Initialize your five tab controllers.  with each tab has its own navigation controller
    HomePageView *homePageView = [[HomePageView alloc]init];
    UINavigationController *nav1 = [[UINavigationController alloc]initWithRootViewController:homePageView];

    ProfileViewController *profileViewController=[[ProfileViewController alloc]init];
    UINavigationController *nav2 = [[UINavigationController alloc]initWithRootViewController:profileViewController];

    FeedViewController *feedViewController=[[FeedViewController alloc]init];
    UINavigationController *nav3 = [[UINavigationController alloc]initWithRootViewController:feedViewController];

    ListeningSessionViewController *listeningSessionViewController= [[ListeningSessionViewController alloc]init];
    UINavigationController *nav4 = [[UINavigationController alloc]initWithRootViewController:listeningSessionViewController];

    RecievedViewController *recievedViewController =[[RecievedViewController alloc]init];
    UINavigationController *nav5 = [[UINavigationController alloc]initWithRootViewController:recievedViewController];

    // initialize tabbarcontroller,set your viewcontrollers and change its color.
    self.tabC = [[UITabBarController alloc]init];
    NSArray* controllers = [NSArray arrayWithObjects: nav1,nav2,nav3,nav4,nav5, nil];
    [self.tabC setViewControllers: controllers animated:NO];
    [_window addSubview:self.tabC.view];

    // Show window
    [self.window makeKeyAndVisible];


    return YES;
}

我猜您正在控制器的viewDidLoad或ViewDidAspect方法中设置标题。这将不起作用,因为虽然所有控制器都在应用程序委托中实例化,但只有索引0处的控制器加载了其视图,因此不会为其他控制器运行viewDidLoad。相反,您应该在app delegate中的导航控制器上设置标题

ProfileViewController *profileViewController=[[ProfileViewController alloc]init];
UINavigationController *nav2 = [[UINavigationController alloc]initWithRootViewController:profileViewController];
nav2.tabBarItem.title = @"Profile";

您现在在哪里设置选项卡栏项目标题?另外,您不应该使用addSubview添加选项卡栏控制器,您应该将选项卡栏控制器设置为窗口的根视图控制器。@rdelmar谢谢,我正在其单独的viewcontoller中添加标题。谢谢rdelmar!我只是愚蠢,这很明显:D