【发布时间】:2020-08-26 12:12:23
【问题描述】:
所以我有一个 UITableView,你可以拖到视图控制器中,而不是 tableviewController。我在 viewDidLoad 中将委托属性设置为 self:
searchTableView.delegate = self
searchTableView.isHidden = true
searchTableView.isUserInteractionEnabled = false
我在故事板中添加了一个原型单元格,其标识符为“SearchResultCell”。这是我的 tableview 数据源函数:
extension MapViewController: UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
searchCompleter.queryFragment = searchBar.searchTextField.text!
let completionResults = searchCompleter.results
return completionResults.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
searchCompleter.queryFragment = searchBar.searchTextField.text!
let completionResults = searchCompleter.results
print(completionResults)
let cell = tableView.dequeueReusableCell(withIdentifier: "SearchResultCell", for: indexPath)
cell.textLabel?.text = completionResults[indexPath.row].subtitle
return cell
}
}
实际上没有调用这些函数中的任何代码。 (别担心,isHidden 和 isUserInteractionEnabled 函数会在我调用表视图函数之前切换,所以这不是问题)我想我没有将这些函数连接到我的特定 UITableView,但我不知道还有什么除了我已经完成的将委托设置为 self 之外,还要做些什么。非常感谢有关如何调用这些的任何建议!
这是我的视图控制器的图片,因此您可以查看缺少约束或定位是否存在问题:
【问题讨论】:
-
另加
searchTableView.dataSource = self -
刚刚添加了它,但我的代码仍然没有被调用
-
它们必须标记为@objc。
-
我刚刚用@objc 标记了函数,但它仍然无法正常工作
标签: ios swift xcode function uitableview