【发布时间】:2016-07-01 12:19:12
【问题描述】:
我在 Xcode 8 beta 中编写了 tableView 的代码,然后尝试在实际的 Xcode 7 中进行。我的下面的代码看起来是正确的,除了 UITableViewDataSource 问题。编译器说:
类型“SettingsVC”不符合协议“UITableViewDataSource”
很奇怪,因为我认为我已经实现了所有必需的方法。
class SettingsVC: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var chooseTable: UITableView!
var tableArray = [String]()
override func viewDidLoad() {
tableArray = ["1", "2", "3", "4", "5"]
}
override func viewDidAppear(animated: Bool) {
chooseTable.reloadData()
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return tableArray.count
}
func tableView(tableView: UITableView, cellForRowAt indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier(tableArray[indexPath.item], forIndexPath: indexPath)
cell.textLabel?.text = tableArray[indexPath.row]
return cell
}
}
附:在 Xcode 8 中,一切都很好。我在使用表的其他 4 个 ViewController 中看到了同样的问题。
【问题讨论】:
-
您是否检查了您尝试使用的功能的签名?
标签: swift uitableview swift3 xcode8