子类有IBOutlet中泰伯维斯威夫特
我在故事板与tableview中这样的视图控制器:子类有IBOutlet中泰伯维斯威夫特
它的阶级是这样的(我联系称为 'tabella' 的IBOutlet中实现代码如下):
class RisultatiRicerca: UIViewController , UITableViewDataSource , UITableViewDelegate{
var codeSearch = 0
@IBOutlet public var tabella : UITableView!
override func viewDidLoad() {
super.viewDidLoad()
self.tabella.estimatedRowHeight = 50
self.tabella.rowHeight = UITableViewAutomaticDimension
self.tabella.delegate = self
self.tabella.dataSource = self
self.tabella.reloadData()
}
@available(iOS 2.0, *)
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cella = tableView.dequeueReusableCell(withIdentifier: "risu") as! CellaRisultato
return cella
}
@available(iOS 2.0, *)
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
return 10
}
}
我的问题是这样的:
我要创建的这个子类上面,比如这个:
class TuttiRicerca: RisultatiRicerca {
override func viewDidLoad() {
super.viewDidLoad()
self.codeSearch = 1
}
}
但是当我提出的TuttiRicerca
我得到这个错误(“tabella”是无):
这就像子犯规情节板中的链接实现代码如下。 你能帮我吗?
如果您需要IBOutlet
的参考资料,您不能只参考TuttiRicera()
。它如何知道你试图使用的故事板中的哪个场景(即使你只有一个场景)?
你需要给故事板场景中的“故事板ID”,然后通过分镜进行实例化(例如storyboard.instantiateViewController(withIdentifier: "...")
,不TuttiRicera()
。见instantiateViewController(withIdentifier:)
。
我用instantiateViewController(withIdentifier :)做了,但我有一个问题:我在故事板中有'RisultatiRicerca'控制器,并通过以下方法实例化它:storyboard?.instantiateViewController(withIdentifier:“ric”)。但我希望它是'TuttiRicerca'类型,但如果我投了,应用程序崩溃(当然) – gianni
我不知道我是否解释得很好,但我会尽量避免为故事板中的每个子类创建一个视图控制器 – gianni
让我们[在聊天中继续讨论](http://chat.*.com/rooms/151801/discussion-between-rob-and-gianni)。 – Rob
你要么失败挂钩出口在故事板,或者,如果你以编程的方式实例化了这个视图控制器,你做得不对,所以检查IB的出口,如果你以编程方式转换到这个场景,那么我们用你的代码 – Rob
在故事板中,我只有控制器关于' RisultatiRicerca'类,它的出口是链接的。我没有控制器关于它的子类 – gianni
istanciate'TuttiRicerca'控制器我只是这样做的:public let viewController1:TuttiRicerca = TuttiRicerca ) – gianni