【发布时间】:2017-09-08 09:25:10
【问题描述】:
我的结构如下:
UIViewController -> UIVIew -> UITableView
tableView(_ tableView: UITableView, numberOfRowsInSection section: Int)
和
tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath)
被调用但是
tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
没有被调用。
class ViewcontrollerA : UIViewController , UITableViewDelegate , UITableViewDataSource {
override func viewDidLoad() {
super.viewDidLoad()
self.doctortableView.delegate = self
self.doctortableView.dataSource = self
self.doctortableView.allowsSelection = true
}
func callTable() {
doctortableView.frame = CGRect(......)
view1.addSubview(doctortableView)
doctortableView.isUserInteractionEnabled = true
self.view.addSubview(view1)
}
// Tableview Functions
// Number of Sections in Table
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
var count = Int()
return count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cell = UITableViewCell()
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
//This function is not called
}
}
【问题讨论】:
-
你怎么知道它没有被调用,你的数据源没有任何行?
-
令人惊讶的是,大量答案出现的速度如此之快,显然所有人都被“未调用某些 tableview 委托方法”所吸引,而不是查看代码,所有这些都只是假设 OP 错过了正确连接委托.
-
@luk2302 我真的不明白,为什么人们在阅读完整问题之前就回复了。
-
因为第一个发帖人“获胜”,如果他们猜对了,那么最快发布答案的人可能会获得最多的支持/接受。
-
@swiftuser123 你有添加手势吗?
标签: ios swift uitableview