0
我試圖在我自己的自定義類中實現Tableview協議。我的目的是開發一個TableView庫。IOS swift3 tableview協議實現在UIController以外的不同類中
我的示例類看起來像這樣
open class TempTableAdapter : NSObject, UITableViewDataSource, UITableViewDelegate{
open var listTable : UITableView!
init(listTable:UITableView) {
super.init()
self.listTable = listTable
self.listTable.dataSource = self
self.listTable.delegate = self
}
open func numberOfSections(in tableView: UITableView) -> Int {
return 1 ;
}
open func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 10
}
open func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "temp") as! TempCell
let text = "hello"
cell.label.text = text
return cell
}
open func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print ("tapped")
}
}
和我的UI控制器看起來像這樣
class ViewController: UIViewController {
@IBOutlet weak var listTable: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
let adap : TempTableAdapter = TempTableAdapter (listTable: listTable)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
任何人都可以指出我錯過了什麼? 問題是UITableView
顯示的是默認表,不使用我的自定義類。
這樣一個愚蠢的錯誤!感謝您的幫助,它現在完美運行。 –