如何在UINavigationController中返回一个视图?

Sle*_*lee 38 cocoa-touch objective-c uinavigationcontroller

有没有办法在堆栈中返回一个视图UINavigationController?或者具有特定标题的视图?

Mat*_*ong 92

我不是故意粗鲁,但这确实是有据可查的.在UINavigationController上进行谷歌搜索甚至是Apple文档搜索都会满足您的需求.要以编程方式弹出当前视图控制器,请使用:

[[self navigationController] popViewControllerAnimated:YES];
Run Code Online (Sandbox Code Playgroud)

要弹出到特定视图控制器,请使用:

[[self navigationController] popToViewController:controller animated:YES];
Run Code Online (Sandbox Code Playgroud)

您必须首先遍历视图控制器列表,然后根据您要查找的内容检查标题,并将其传递给此方法.

  • 大声笑,你是对的 - 这很傻.我甚至多次看过那种方法.在我的辩护中,我对此非常陌生,并且仍然掌握了概念 - 尽管popViewController几乎是自我解释,当你的新事物不会马上点击​​时. (3认同)

Tom*_*ing 6

看看popViewControllerAnimated:.

从文档: This method removes the top view controller from the stack and makes the new top of the stack the active view controller.

用法类似于:

[aViewController popViewControllerAnimated:YES];
Run Code Online (Sandbox Code Playgroud)