UITabBarController无法设置初始视图

时间:2014-02-10 22:39:03

标签: objective-c uitabbarcontroller

我今天早些时候问了一个类似的问题,但我遇到了问题。当我的应用程序加载时,我正在尝试加载第三个视图tabbarcontroller。我在appdelegate中有以下内容,但第一个视图仍在加载。

appdelegate.m:

    UITabBarController *tbc = [[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:@"tbc"];

    [tbc setSelectedIndex:2];
    [self.window setRootViewController:tbc];
    [self.window makeKeyAndVisible];

    return YES;

Appdelegate.h:

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>


@property (strong, nonatomic) UIWindow *window;
@property(nonatomic,strong) UITabBarController *tbc;

@end

我确信这是我错过的基本内容。

1 个答案:

答案 0 :(得分:0)

一些细节:

  1. 您是否初始化了self.window,例如

    之类的东西
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    


    您应该设置一个断点,并确保在self.window之前makeKeyAndVisible为非零。

  2. 您声明tbc的方式是作为局部变量。如果要初始化声明为属性的实例变量,它应该是这样的:

    self.tbc = [[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:@"tbc"];
    
相关问题