表视图控制器

时间:2017-03-03 19:35:36

标签: swift uitableview uiviewcontroller tableview viewcontroller

我收到一条错误消息,其中显示"输入'查看控制器'不符合协议' 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)
    }
}

1 个答案:

答案 0 :(得分:2)

添加这两个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
相关问题