我有一個問題時,把UITableView到UIView。UITableView裏面UIView在Swift 3.0
我設置了一個代表和數據源並實現所有方法。
這是我的UIView類。
@objc class ChooserView: UIView, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var backgroundView: UIView!
@IBOutlet weak var showView: UIView!
@IBOutlet weak var tableView: UITableView!
public class func createChooserView() -> ChooserView {
var view: ChooserView!
view = Bundle.main.loadNibNamed(String(describing: ChooserView.self), owner: self, options: nil)?.first as! ChooserView
_ = MLAutolayouts.fillContainer(UIApplication.shared.keyWindow!.subviews.first!, view: view)
//Register cell nib
view.tableView.register(UINib(nibName: "PhoneCell", bundle: nil), forCellReuseIdentifier: "PhoneCell")
return view
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: PhoneCell.self)) as! PhoneCell
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print("TAP...")
}
}
這是outles
當運行我的應用程序。我得到這個錯誤
-[UIView tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x7fded2e772d0
Log img。
任何想法...
感謝。
你宣佈你在代碼中的類,但看起來你忘了聲明在您的視圖IB有類的類型,這就是爲什麼你看到' - [UIView tableView:numberOfRowsInSection:]'而不是' - [ChooserView ...' – Ossir
如何連接UIView? @Hasham –