如何按“返回”键以编程方式在 UINavigationController 中按钮
我在 UINavigationController
中有一个名为 FriendsViewController
的 UIViewController
。第二个 UIViewController
称为 FriendsDetailedViewController
。从第一个视图控制器导航到第二个视图控制器时,我想在需要时以编程方式按 Back
按钮。如何做到这一点?
I have a UIViewController
called FriendsViewController
inside a UINavigationController
. And a second UIViewController
called FriendsDetailedViewController
. When navigating from the first view controller to the second, I want to programmatically press the Back
button when needed. How to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
只需使用
FriendsDetailedViewController 中的
[self.navigationController popViewControllerAnimated:YES]
即可。您的视图将弹出,即后退按钮的行为。
Simply use
[self.navigationController popViewControllerAnimated:YES]
from FriendsDetailedViewController. Your view will be popped out i.e. the behavior of back button.
如果按“后退”按钮只是想转到上一个视图控制器,则可以调用:
If by pressing "Back" button you mean just to go to the previous view controller, you can just call:
这是快速方法
Here is the swift method
Swift 5
代码片段中的用法:
Swift 5
Usage in a code snippet:
1) 当您弹出当前的 NavigationController 时,然后
在 Swift 中
Objective C
2) 当您返回另一个导航控制器时,然后
在 Swift 中
在 Objective 中C
1) When you pop in current NavigationController Then
In Swift
Objective C
2) When you back another Navigation controller Then
In Swift
In Objective C
这是我在 Swift 3 中的做法
_
用于抑制 XCode 生成的丑陋警告。Here is how I did it in Swift 3
_
is used to suppress the ugly warning generated by XCode.