UINavigationController 更改子视图与另一个
我在导航控制器中有以下结构
RootViewController
|
|--FirstViewController
|
|--SecondViewController
如何直接从 FirstViewController
跳转到 SecondViewController
而不显示 RootViewController
。我想在 FirstViewController 的导航栏中添加一个按钮,例如“转到 SecondViewController”。
I have the following structure in Navigation Controller
RootViewController
|
|--FirstViewController
|
|--SecondViewController
How can I jump directly from FirstViewController
to SecondViewController
without showing RootViewController
. I would like to put a button to the FirstViewController
's NavigationBar like "Go to SecondViewController."
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在相应按钮的操作方法中,初始化
SecondViewController
,然后组装一个由两个元素组成的 NSArray:RootViewController
和新初始化的SecondViewController
(在该顺序,即索引 0 处的Root
和索引 1 处的Second
)。然后调用 NavigationController 的 setViewControllers:animated: 方法,并将视图控制器数组作为第一个参数传递。请记住在调用此方法后
release
SecondViewController
,或者在初始化时autorelease
它以避免内存泄漏。澄清一下,这将导致 FirstViewController 被 NavigationController 释放。
示例:
参考: UINavigationController 类参考
In the appropriate button's action method, initialize the
SecondViewController
, then assemble an NSArray consisting of two elements: theRootViewController
and the newly initializedSecondViewController
(in that order, i.e.Root
at index 0 andSecond
at index 1).Then call the NavigationController's
setViewControllers:animated:
method, and pass the array of view controllers as the first argument. Remember torelease
theSecondViewController
after calling this method, orautorelease
it upon initialization to avoid a memory leak.Just to clarify, this will cause the
FirstViewController
to be released by the NavigationController.Sample:
Reference: UINavigationController Class Reference