I am currently creating a custom view. This view has a UITableView
with it. The delegate for this control will be the backing class for the custom control.
class MyView: UIView {
@IBOutlet weak var autoCompleteView: UITableView!
}
extension MyView: UITableViewDelegate {
}
extension MyView: UITableViewDataSource {
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "reuseIdentifier", for: indexPath as IndexPath)
cell.textLabel!.text = "\(indexPath.row) - Its working"
return cell
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 2
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 2
}
}
Now at some point here, in this class, I need to get the delegate for the UITableView
but that can only happen once the view has been loaded (otherwise autoCompleteView
will be nil
).
If it were in a UIViewController
I could simply add it to viewDidLoad
but I dont have that open here. So how can I go about setting the delegate for the UITableView