Reputation: 123
I have a view controller in storyboard with tableview like this:
It's class is this (I linked the iboutlet tableview called 'tabella'):
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
}
}
My problem is this:
I have to create a subclass of this above, for example this:
class TuttiRicerca: RisultatiRicerca {
override func viewDidLoad() {
super.viewDidLoad()
self.codeSearch = 1
}
}
but when I present the TuttiRicerca
I get this error ('tabella' is nil):
It's like subclass doesnt link the tableview in the storyboard. Can you help me?
Upvotes: 2
Views: 656
Reputation: 437692
If you want IBOutlet
references, you cannot just reference TuttiRicera()
. How does it know which scene in your storyboard you're trying to use (even if you only have one)?
You need to give the storyboard scene a "storyboard id" and then instantiate it via the storyboard (e.g. storyboard.instantiateViewController(withIdentifier: "...")
, not TuttiRicera()
. See instantiateViewController(withIdentifier:)
.
Upvotes: 1