【问题标题】:Type 'ViewController' does not conform to protocol类型“ViewController”不符合协议
【发布时间】: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
    }
}

这是我迄今为止尝试过的:

  1. 我已确保该函数在类中。
  2. 我已确保 ViewController 插座是主要故事板。
  3. 阅读其他具有类似问题的 StackOverflow 问题,我找不到解决方案。 (我可能会错过)。

谢谢

【问题讨论】:

  • 你缺少 numberOfRows。
  • 这两种方法对于 UITableViewDataSource 协议 cellForRow 和 numberOfRowsInSection 都是强制的
  • 没错。
  • 帮助自己的提示:在问题导航器中,单击错误消息旁边的显示三角形并阅读缺少哪些方法。

标签: ios swift xcode viewcontroller


【解决方案1】:

您还需要实现其他方法。在这里你不见了

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int{

    return GetAllDataTest.count
}

【讨论】:

  • 谢谢,太好了!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-17
  • 2014-11-08
  • 1970-01-01
相关资源
最近更新 更多