且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何以编程方式在视图中嵌入导航控制器?

更新时间:2023-02-16 08:42:59

使用您的 StackTableViewController 作为其 rootViewController 创建 UINavigationController 的新实例.>.然后显示导航控制器:

Create a new instance of UINavigationController, with your StackTableViewController as its rootViewController. Then present the navigation controller:

- (IBAction)pushToNextViewController:(id)sender {

    StackTableViewController *vc = [[StackTableViewController alloc]init];
    UINavigationController *navCtrl = [[UINavigationController alloc] initWithRootViewController:vc];
    [self presentViewController:navCtrl animated:YES completion:nil];

}

请注意,不赞成使用 presentModalViewController:animated:,因为它已由 presentViewController:animated:completion:代替.

Note that presentModalViewController:animated: is deprecated because it has been replaced by presentViewController:animated:completion:.