在UINavigationController中包装UIViewController

Sun*_*day 5 uiviewcontroller uinavigationcontroller ios

我希望我的视图控制器有自己的导航栏.我发现这比显示/隐藏现有导航栏更容易.以下代码正在运行.这是反模式还是相对常见的做法?

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

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

[self.navigationController presentViewController:wrapper 
                                        animated:YES 
                                      completion:nil];
Run Code Online (Sandbox Code Playgroud)

Joe*_*kin 5

要呈现带有导航栏和自己的导航堆栈的模态视图控制器,您发布的代码是完全正确的.你应该注意的唯一事情是第二个UINavigationController推送到现有的导航控制器的堆栈 - 这将导致你的问题.

  • 没有不同.即使你调用`[self presentViewController:...]`,它也会显示在包装器的`presentsViewController`属性中的`self.navigationController`. (2认同)