【发布时间】:2017-07-30 13:23:18
【问题描述】:
我正在学习 Swift 并遵循一些教程。我不断收到错误消息: 输入
'ViewController' 不符合协议 'UITableViewDataSource'
import UIKit
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
var GetAllDataTest = NSMutableArray()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func viewWillAppear(_ animated: Bool) {
GetAllDataTest = FMDBDatabaseModel.getInstance().GetAllData()
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "TestTableViewCell") as! TestTableViewCell
//cell.editData = self
cell.tag = indexPath.row
var l = Tbl_Test()
l = GetAllDataTest.object(at: indexPath.row) as! Tbl_Test
cell.lblName.text! = l.Name
cell.lblMobileNo.text! = l.MobileNo
cell.lblEmail.text! = l.Email
return cell
}
}
这是我迄今为止尝试过的:
- 我已确保该函数在类中。
- 我已确保 ViewController 插座是主要故事板。
- 阅读其他具有类似问题的 StackOverflow 问题,我找不到解决方案。 (我可能会错过)。
谢谢
【问题讨论】:
-
你缺少 numberOfRows。
-
这两种方法对于 UITableViewDataSource 协议 cellForRow 和 numberOfRowsInSection 都是强制的
-
没错。
-
帮助自己的提示:在问题导航器中,单击错误消息旁边的显示三角形并阅读缺少哪些方法。
标签: ios swift xcode viewcontroller