类型“ViewController"不符合协议“UITableViewDataSource" [英] Type 'ViewController' does not conform to protocol 'UITableViewDataSource'

查看:35
本文介绍了类型“ViewController"不符合协议“UITableViewDataSource"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

开始快速练习.在 singleViewController 我试图制作一个 UITableView.在故事板中,我设置了数据源和委托.在这里我收到错误 * 'ViewController' 不符合协议 'UITableViewDataSource' *

Started practice swift. In singleViewController I am trying to make a UITableView. In storyboard I set the datasource and delegate. Here I am getting the error * 'ViewController' does not conform to protocol 'UITableViewDataSource' *

class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
    @IBOutlet weak var table: UITableView!


    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

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


}

func numberOfSectionsInTableView(tableView: UITableView!) -> Int
{
    return 20
}
func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell!
{
    let cell:UITableViewCell=UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "mycell")
cell.textLabel.text="row#(indexPath.row)"
    cell.detailTextLabel.text="subtitle#(indexPath.row)"

    return cell

}

推荐答案

您应该在最后一个 } 之前实现所有必需的方法,但是您已经在 UIViewController 之外编写了它们.此外,您需要更改行数的功能.

You should implement all the required methods before the last }, but you have written them outside of the UIViewController. Also, you need to change the func for number of lines.

建议的编辑

class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
    @IBOutlet weak var table: UITableView!


    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

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

    func tableView(tableView:UITableView!, numberOfRowsInSection section:Int) -> Int
    {
        return 20
    }

    func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell!
    {
        let cell:UITableViewCell=UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "mycell")
        cell.textLabel.text="row#(indexPath.row)"
        cell.detailTextLabel.text="subtitle#(indexPath.row)"

        return cell
    }
}

这篇关于类型“ViewController"不符合协议“UITableViewDataSource"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆