Table 视图控制器

Table View Controller

我收到一条错误消息 "Type 'View Controller' does not conform to protocol 'UITableViewDataSource'"

 import UIKit

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

}
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        self.performSegue(withIdentifier: "meunSegue", sender: self)
    }
    func prepare(for segue: UIStoryboardSegue, sender: Any?) {


        let secondViewController = segue.destination as! SecondViewController
        secondViewController.recievedData = "hello"
    }

class SecondViewController: UIViewController {

    var recievedData = ""
    override func viewDidLoad() {
        super.viewDidLoad()
        print(recievedData)
    }
}

添加这两个tableView委托方法:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    return UITableViewCell()
}

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

确保将 table 委派设置为 ViewController

table.delegate = self
table.dataSource = self