简体   繁体   中英

Type 'ViewController' does not conform to protocol

I'm learning Swift and following some tutorials. I keep getting an error: Type

'ViewController' does not conform with protocol '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
    }
}

Here is what I have tried so far:

  1. I have ensured the function is inside the Class.
  2. I have ensured theViewController outlets are the main story board.
  3. Read other StackOverflow questions with similar issues, no solution I can find. (I could have missed it).

Thanks

You need to implement other methods as well. Here you are missing

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

    return GetAllDataTest.count
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM