1

我正在尝试在我的 iOS 项目中使用导航控制器。这是我的 AppDelegate 类的设置:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    // Generate RootViewController (some auto-layout stuff is going on here)
    MyLayoutDescriptionGeneratorClass *generator = [MyLayoutDescriptionGeneratorClass new];
    MyViewControllerClass *vc = [generator generateViewController];

    self.navController = [[UINavigationController alloc] initWithRootViewController:vc];
    [self.window setRootViewController:self.navController];
    [self.window makeKeyAndVisible];
    return YES;
}

我的viewDidLoad视图控制器看起来像这样:

-(void)viewDidLoad{

    [super viewDidLoad];
    // Generate all subviews and their constraints        
    self.view = [MyObjectManagerClass viewForParentViewDescription:_parentViewDescription];
    self.title = @"Hello";
}

当我构建并运行时,会显示导航栏,并且它的标题设置为Hello- 不幸的是,视图控制器视图没有显示。

如果我像这样取出导航控制器

[self.window setRootViewController:self.navController];

一切都很好。任何人都可以帮助我吗?

4

1 回答 1

1

我只需要修改我的viewDidLoad

-(void)viewDidLoad{
    [super viewDidLoad];
    // Generate all subviews and their constraints        
    UIView *view = [RuiObjectManager viewForParentViewDescription:_parentViewDescription];
    self.title = @"Hello";

    // Add generated view to self.view and create constraints
    [self.view addSubview:view];
    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[view]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(@"view", view)]];
    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[view]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(@"view", view)]];
}
于 2013-06-11T17:35:37.117 回答