xcode 关闭模态视图 Swift
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25587993/
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
Dismissing Modal View Swift
提问by rocket101
EDIT: Thanks to the person behind the answer below, who fixed the unknown class. However, can anyone tell me if the code to dismiss is correct? I am on vacation and can't program until I get back.
编辑:感谢下面答案背后的人,他修复了未知类。但是,谁能告诉我解雇的代码是否正确?我正在休假,在我回来之前无法编程。
I am developing an app in Swift. Currently, I am working on an info screen (legal notices, credits, documentation, etc) that will be presented modally atop the main screen.
我正在 Swift 中开发一个应用程序。目前,我正在处理一个信息屏幕(法律通知、信用、文档等),它将在主屏幕上以模态呈现。
The expected behavior is that, when a button press triggers Dismiss
in InfoViewController
, the modal view controller is dismissed.
预期的行为是,当在 中触发按钮按下Dismiss
时InfoViewController
,模态视图控制器将被解除。
Here's the code I'm trying to use:
这是我尝试使用的代码:
//This is InfoViewController, the swift file used to conorol the info screen.
import UIKit
class InfoViewController: UIViewController {
@IBAction func Dismiss(sender: AnyObject) {
self.dismissViewControllerAnimated(true, completion: {});//This is intended to dismiss the Info sceen.
println("pressed")
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
}
Here's the layout of the storyboards:
这是故事板的布局:
When I press the button, the app crashes and doesn't dismiss the modal view controller.
当我按下按钮时,应用程序崩溃并且不会关闭模态视图控制器。
It compiles, suggesting it is not a syntactual error.
它编译,表明它不是语法错误。
Here's the LLVM debugger output:
这是 LLVM 调试器输出:
2014-08-30 20:02:20.571 CryptoCalc[799:244086] 17545849:_UIScreenEdgePanRecognizerEdgeSettings.edgeRegionSize=13.000000 //Unrelated stuff deleted. 2014-08-30 20:03:03.756 CryptoCalc[799:244086] Unknown class InfoViewController in Interface Builder file. 2014-08-30 20:03:20.485 CryptoCalc[799:244086] -[UIViewController Dismiss:]: unrecognized selector sent to instance 0x14d57990 2014-08-30 20:03:20.489 CryptoCalc[799:244086] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController Dismiss:]: unrecognized selector sent to instance 0x14d57990' *First throw call stack: (0x2238be2f 0x2f46bc8b 0x22391179 0x2238f097 0x222c11f8 0x259b9fef 0x259b9f91 0x259a4d13 0x259b99fd 0x259b96d7 0x259b2fa1 0x25989a09 0x25bfbae3 0x259884a1 0x2235257f 0x2235198f 0x2234fff5 0x2229e611 0x2229e423 0x297f80a9 0x259e8485 0x73720 0x7375c 0x2f9f1aaf) libc++abi.dylib: terminating with uncaught exception of type NSException
2014-08-30 20:02:20.571 CryptoCalc[799:244086] 17545849:_UIScreenEdgePanRecognizerEdgeSettings.edgeRegionSize=13.000000 //无关的东西被删除了。2014-08-30 20:03:03.756 CryptoCalc[799:244086] Interface Builder 文件中的未知类 InfoViewController。2014-08-30 20:03:20.485 CryptoCalc[799:244086] -[UIViewController Dismiss:]: 无法识别的选择器发送到实例 0x14d57990 2014-08-30 20:03:20.4879092由于应用程序 *TerCalc4未捕获的异常 'NSInvalidArgumentException',原因:'-[UIViewController Dismiss:]:无法识别的选择器发送到实例 0x14d57990'*第一掷调用堆栈:(0x2238be2f 0x2f46bc8b 0x22391179 0x2238f097 0x222c11f8 0x259b9fef 0x259b9f91 0x259a4d13 0x259b99fd 0x259b96d7 0x259b2fa1 0x25989a09 0x25bfbae3 0x259884a1 0x2235257f 0x2235198f 0x2234fff5 0x2229e611 0x2229e423 0x297f80a9 0x259e8485 0x73720 0x7375c 0x2f9f1aaf)的libc ++ abi.dylib:与类型NSException的未捕获的异常终止
If you need any more info, let me know. Thanks so much.
如果您需要更多信息,请告诉我。非常感谢。
采纳答案by Anthony Kong
The main issue here is Unknown class InfoViewController in Interface Builder file.
这里的主要问题是 Unknown class InfoViewController in Interface Builder file.
You need to make sure that (in 'Custom Class' section)
您需要确保(在“自定义类”部分)
1) The class in the storyboard is set to InfoViewController
1)storyboard中的class设置为 InfoViewController
2) The module is set to 'Current - your project name'
2)模块设置为“当前 - 您的项目名称”
screen shot include to show which part of Interface builder I am referring to
屏幕截图包括显示我所指的界面构建器的哪一部分