Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/103.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios “类型”;“视图控制器”;不符合协议';UITableViewDataSource“;_Ios_Swift - Fatal编程技术网

Ios “类型”;“视图控制器”;不符合协议';UITableViewDataSource“;

Ios “类型”;“视图控制器”;不符合协议';UITableViewDataSource“;,ios,swift,Ios,Swift,我在编码时出错,说 类型“ViewController”不符合协议“UITableViewDataSource” 谁能说出这出了什么问题 import UIKit class ViewController: UIViewController, UITableViewDataSource{ let devCourses = [ ("Math"), ("Science"), ("English"), ("Computer P

我在编码时出错,说

类型“ViewController”不符合协议“UITableViewDataSource”

谁能说出这出了什么问题

import UIKit

class ViewController: UIViewController, UITableViewDataSource{

    let devCourses = [
        ("Math"),
        ("Science"),
        ("English"),
        ("Computer Programming"),
        ("Physics")]
    func numberOfSectionsInTableview(tableview: UITableView)-> Int {
        return 1
    }
    func tableview(tableView: UITableView, numberOfRowsInSection section: Int) ->Int{
         return devCourses.count
    }
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = UITableViewCell()

        let (courseTitle) = devCourses[indexPath.row]

        cell.textLabel?.text = courseTitle
        return cell
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}

我认为您缺少代表要求的一些功能:

声明应更改为包括:

class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
然后确保表的所有必需方法都存在:

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

并在
ViewDidLoad

override func viewDidLoad() {
    super.viewDidLoad()

      yourtableview.dataSource = self

    // Do any additional setup after loading the view.
}

希望这有帮助这是一个常见的错误,请确保使用正确的单词。在您的情况下,它应该是:

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
     return devCourses.count
}
不是


您必须使用tableView而不是tableView。它区分大小写

您是否尝试将父级更改为UITableViewController?我将“tableview”改为“tableview”,这就是我出错的原因。谢谢大家的帮助!
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
     return devCourses.count
}
func tableview(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return devCourses.count
}