将 UIKit 连接到代码
Connecting UIKit to Code
我已尝试按照 here 中提到的说明将 UI 组件连接到我的视图控制器。虽然,每当我生成行
@IBOutlet weak var mt: UITextView!
当我 运行 我的应用程序在使用消息
启动 segue 后发送 SIGABRT
Terminating app due to uncaught exception 'NSUnknownKeyException',
reason: '[<UIViewController 0x10336c400> setValue:forUndefinedKey:]:
this class is not key value coding-compliant for the key mt.'
我看过其他帖子,这不可能死link因为我刚刚创建它,当我删除引用插座时,应用程序不再崩溃。
有人可以告诉我如何解决这个问题吗?所有相关代码如下。
ViewController
performSegue(withIdentifier: "mySegueID", sender: nil)
...
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if (segue.identifier == "mySegueID") {
if let destinationViewController = segue.destination as? MessageViewController {
destinationViewController.message = "Hi friend"
}
}
}
留言ViewController
import UIKit
class MessageViewController: UIViewController {
var message:String = "default"
@IBOutlet weak var mt: UITextView!
override func viewDidLoad(){
super.viewDidLoad()
mt.text = message
}
}
提前致谢!
所以我想通了!导致错误的原因是自定义 class 未被识别。通过单击 "Inherit Module from Target",它解决了问题。
我已尝试按照 here 中提到的说明将 UI 组件连接到我的视图控制器。虽然,每当我生成行
@IBOutlet weak var mt: UITextView!
当我 运行 我的应用程序在使用消息
启动 segue 后发送 SIGABRTTerminating app due to uncaught exception 'NSUnknownKeyException',
reason: '[<UIViewController 0x10336c400> setValue:forUndefinedKey:]:
this class is not key value coding-compliant for the key mt.'
我看过其他帖子,这不可能死link因为我刚刚创建它,当我删除引用插座时,应用程序不再崩溃。
有人可以告诉我如何解决这个问题吗?所有相关代码如下。
ViewController
performSegue(withIdentifier: "mySegueID", sender: nil)
...
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if (segue.identifier == "mySegueID") {
if let destinationViewController = segue.destination as? MessageViewController {
destinationViewController.message = "Hi friend"
}
}
}
留言ViewController
import UIKit
class MessageViewController: UIViewController {
var message:String = "default"
@IBOutlet weak var mt: UITextView!
override func viewDidLoad(){
super.viewDidLoad()
mt.text = message
}
}
提前致谢!
所以我想通了!导致错误的原因是自定义 class 未被识别。通过单击 "Inherit Module from Target",它解决了问题。