ios - 在 UINavigationController 中包装 UIViewController

标签 ios uiviewcontroller uinavigationcontroller

我希望我的 View Controller 有自己的导航栏。我发现这比显示/隐藏现有的导航栏更容易。以下代码正在运行。 这是反模式还是相对普遍的做法?

MyViewController *viewController = [[MyViewController alloc] init] 
                                    autorelease];

UINavigationController *wrapper = [[[UINavigationController alloc] 
                                   initWithRootViewController:viewController] 
                                    autorelease];

[self.navigationController presentViewController:wrapper 
                                        animated:YES 
                                      completion:nil];

最佳答案

要呈现带有导航栏及其自己的导航堆栈的模态视图 Controller ,您发布的代码是完全正确的。您唯一应该注意的是第二个 UINavigationController 推到现有导航 Controller 的堆栈上——这会给您带来问题。

关于ios - 在 UINavigationController 中包装 UIViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12697754/

相关文章:

ios - 如何显示多个本地通知?

ios - 将新的 View Controller 添加到选项卡 Controller

显示提示时 iOS5 UINavigationBar 背景图像问题

ios - UISplitViewController 中嵌入的 UIViewController 在 iPhone 上不显示栏按钮

ios - 是否可以在 XIB 中为 Root View 设置约束?

IOS 删除每个标签栏项目之间的空间

iOS同时使用CLLocation和MapView获取坐标和更新 map

ios - Swift - 将字符串从 VC1 传递到 VC2 - 崩溃

ios - 将 UIViewController subview 重置回初始位置

ios - 如何使用 subview 自定义底部选项卡栏对 UINavigationController 进行子类化