ios 关闭通过模态转场显示的视图
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8513319/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Closing a view displayed via a modal segue
提问by Nick
I'm manually invoking a segue (set as modal) in order to display a login form in Xcode 4.2 using Storyboards with the following line of code:
我正在手动调用 segue(设置为模式),以便在 Xcode 4.2 中使用带有以下代码行的 Storyboards 显示登录表单:
[self performSegueWithIdentifier:@"LoginSegue" sender:nil];
I'm probably missing something really simple, however I can't find a way to programmatically close the login view and return to the previous view.
我可能遗漏了一些非常简单的东西,但是我找不到以编程方式关闭登录视图并返回到上一个视图的方法。
The view is part of a navigation view controller, so setting the segue type to "push" allows me to use the back button to send me back to my previous screen, but in "modal" mode, I'm not entirely sure how to achieve this (after button press, for example)
该视图是导航视图控制器的一部分,因此将 segue 类型设置为“push”允许我使用后退按钮将我发送回上一个屏幕,但在“模态”模式下,我不完全确定如何实现这一点(例如,按下按钮后)
Any help would be much appreciated.
任何帮助将非常感激。
回答by rob mayoff
If your deployment target is iOS 5.0 or later, use this message:
如果您的部署目标是 iOS 5.0 或更高版本,请使用以下消息:
[self dismissViewControllerAnimated:YES completion:nil];
Or in Swift:
或者在 Swift 中:
self.dismissViewControllerAnimated(true, completion: nil)
If your deployment target is older, use this (deprecated) message:
如果您的部署目标较旧,请使用此(已弃用)消息:
[self dismissModalViewControllerAnimated:YES];
回答by denny
[self dismissViewControllerAnimated:YES completion:nil];
is a new way in IOS5
[self dismissViewControllerAnimated:YES completion:nil];
是IOS5的新方式
回答by Simon
The following should work fine...
以下应该工作正常......
[self dismissModalViewControllerAnimated:YES];
I do exactly this with a login page in my latest tutorial here, with no issues.
我在我的最新教程中的登录页面正是这样做的,没有任何问题。
回答by Bogdan Razvan
The following code works in swift 3:
以下代码适用于 swift 3:
self.dismiss(animated: true, completion: nil)