如何从其子类正确访问超类视图控制器的IBOutlet属性?
我有一个DetailViewController和一个AddViewController,它是DetailViewController的子类。在DetailVC中,我有一堆textViews作为从情节提要板连接的IBOutlet属性。我想在AddVC中使用这些textView,但是总是找不到。
// These textViews are connected to storyboard's DetailViewController from DetailViewController
@IBOutlet var textViews: [KMPlaceholderTextView]!
// I'm trying to access those textViews from AddViewController which is a subclass of DetailViewController, but they are nil
class JLAddViewController: JLDetailViewController {
// MARK: - *****数据源*****
// 用来接收主控制器搜索框上的单词
var word:String?
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
// 打开每个textView的输入功能
textViews.forEach {
$0.isUserInteractionEnabled = true;
$0.isEditable = true
}
}
}
答案 0 :(得分:2)
情节提要中的视图控制器不是类而是实例。您为DetailViewController实例设计的接口和插座属于该实例,而不属于其他某个实例,当然也不属于子类的实例。