【发布时间】:2017-02-01 18:00:14
【问题描述】:
将 UITableView 放入 UIView 时出现问题。
我设置了 delegate 和 datasource 并实现所有方法。
这是我的 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...")
}
}
这就是出口
当运行我的应用程序时。我收到此错误
-[UIView tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x7fded2e772d0
记录图片。
任何想法...
谢谢。
【问题讨论】:
-
您已经在代码中声明了您的类,但您似乎忘记声明您在 IB 中的视图具有您的类的类型,这就是为什么您看到
-[UIView tableView:numberOfRowsInSection:]而不是-[ChooserView ... -
如何连接UIView?? @哈希姆
标签: ios uitableview swift3