【发布时间】:2017-07-31 07:00:44
【问题描述】:
我目前正在创建自定义视图。这个视图有一个UITableView。此控件的委托将是自定义控件的支持类。
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
}
}
现在,在这个类中,我需要获取UITableView 的委托,但这只能在视图加载后发生(否则autoCompleteView 将是nil)。
如果它在UIViewController 中,我可以简单地将它添加到viewDidLoad,但我没有在这里打开它。那么我该如何设置UITableView的委托
【问题讨论】:
标签: ios swift uitableview uiview