我目前正在創建自定義視圖。這個視圖有一個UITableView
。該控件的委託將成爲自定義控件的後備類。如何確定UIView是否已加載
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