UITableViewDataSource 想要 smth
UITableViewDataSource wants smth
我在 Xcode 8 beta 中编写了 tableView 的代码,然后尝试在实际 Xcode 7 中执行它。除了 UITableViewDataSource 问题,我下面的代码看起来是正确的。编译器说:
Type 'SettingsVC' does not conform to protocol '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
}
}
P.S。在 Xcode 8 中一切正常。我在其他 4 个使用表的 ViewControllers 中看到了同样的问题。
Xcode 7 不支持 swift 3.0,而您正在为 UITableViewDataSource
使用 Swift 3.0 方法
替换:
func tableView(tableView: UITableView, cellForRowAt indexPath: NSIndexPath) -> UITableViewCell {
与:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
干杯
我在 Xcode 8 beta 中编写了 tableView 的代码,然后尝试在实际 Xcode 7 中执行它。除了 UITableViewDataSource 问题,我下面的代码看起来是正确的。编译器说:
Type 'SettingsVC' does not conform to protocol '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
}
}
P.S。在 Xcode 8 中一切正常。我在其他 4 个使用表的 ViewControllers 中看到了同样的问题。
Xcode 7 不支持 swift 3.0,而您正在为 UITableViewDataSource
替换:
func tableView(tableView: UITableView, cellForRowAt indexPath: NSIndexPath) -> UITableViewCell {
与:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
干杯