【问题标题】:ViewController does not conform to protocol 'UITableViewDataSourceViewController 不符合协议 'UITableViewDataSource
【发布时间】:2016-11-07 00:09:24
【问题描述】:

**哪里出错了?

错误“SecondViewController 不符合协议'UITableViewDataSource”**

导入 UIKit

SecondViewController 类:UIViewController、UITableViewDataSource、UITableViewDelegate

{

@IBOutlet weak var tableView: UITableView!
var videos:[video] = [video]()

@IBOutlet weak var menuButton: UIBarButtonItem!
override func viewDidLoad() {
    super.viewDidLoad()




        if self.revealViewController() != nil {
        menuButton.target = self.revealViewController()
        menuButton.action = #selector(SWRevealViewController.revealToggle(_:))
        self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())


        let model = videoModel()
        self.videos = videoModel().getVideos()

        self.tableView.dataSource = self
        self.tableView.delegate = self

    }

func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }


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


func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "BasicCell", for: indexPath)

        let videoTitle = videos[indexPath.row].videoTitle

        //customize the cell
    cell.textLabel?.text = videoTitle


    return cell

    }

}

}

【问题讨论】:

  • 请不要将您的代码作为图片发布。将实际的相关代码复制并粘贴到您的问题中。

标签: swift swift3


【解决方案1】:

也许,你没有连接 UIViewController 和 UITableView。

在 Stroyboard 中, 将鼠标放在 UITableView 上,使用右键拖动到 UIViewController。然后你可以检查出口选项、数据源和委托。检查这些。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多