简体   繁体   English

ViewController不符合协议UITableViewDataSource

[英]ViewController does not conform to protocol UITableViewDataSource

I ran into a problem recently. 我最近遇到了一个问题。

在此处输入图片说明

I'll post some code too. 我也将发布一些代码。 Tried the methods from internet but without success. 尝试了互联网上的方法,但没有成功。 Also, I have linked the 2 tables to the View Controller. 另外,我已将2个表链接到视图控制器。

在此处输入图片说明

Here is some code. 这是一些代码。

class ViewController2: UIViewController, UITableViewDataSource, UITableViewDelegate {

    @IBOutlet weak var carImageView: UIImageView!
    @IBOutlet weak var pieseDorite: UITableView!
    @IBOutlet weak var pieseDisponibile: UITableView!


    var fullNameArr : [String] = [] // i populate the string in a action button, no problem with the arrays
    var fullNameArrDorit : [String] = []

    override func viewDidLoad()
    {
        super.viewDidLoad()
        carImageView.image = UIImage(named: ("simplu"))
        carImageView.contentMode = .ScaleAspectFit

        pieseDisponibile.delegate = self
        pieseDisponibile.dataSource = self
        self.view.addSubview(pieseDisponibile)

        pieseDorite.delegate = self
        pieseDorite.dataSource = self
        self.view.addSubview(pieseDorite)
    }


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

    func tableView(pieseDisponibile: UITableView, pieseDorite: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
    {

        let cell:UITableViewCell=UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "cell")
        cell.textLabel!.text = String(fullNameArr[indexPath.row])
        return cell
    }

    func tableView2(pieseDorite: UITableView, numberOfRowsInSection section:Int) -> Int
    {
        return fullNameArrDorit.count
    }

    func tableView2(pieseDorite: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
    {

        let cell2:UITableViewCell=UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "cell2")
        cell2.textLabel!.text = String(fullNameArrDorit[indexPath.row])
        return cell2
    }

}

Also, tried to add all other functions, the problem persisted. 此外,尝试添加所有其他功能,问题仍然存在。 I think I have linked something bad, I don't know. 我想我联系的不好,我不知道。

Replace all tableView2 with tableView please, and leave only 1 each method. 请用tableView替换所有tableView2 ,每个方法只保留1个。 You need have same delegate methods for all UITableView instances. 您需要为所有UITableView实例使用相同的委托方法。 You can separate different instances inside this methods by comparing first parameter with your UITableView property. 通过将第一个参数与UITableView属性进行比较,可以在此方法内分隔不同的实例。 Also add number of section method: 还要添加节号方法:

override func viewDidLoad()
{
    super.viewDidLoad()
    carImageView.image = UIImage(named: "simplu")
    carImageView.contentMode = .ScaleAspectFit

    pieseDisponibile.delegate = self
    pieseDisponibile.dataSource = self
    view.addSubview(pieseDisponibile)

    pieseDorite.delegate = self
    pieseDorite.dataSource = self
    view.addSubview(pieseDorite)
}

func numberOfSectionsInTableView(tableView: UITableView) -> Int {return 1}

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
    if tableView == pieseDisponibile {return fullNameArr.count}
    return fullNameArrDorit.count
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
    if tableView == pieseDisponibile {
        let cell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "cell")
        cell.textLabel?.text = String(fullNameArr[indexPath.row])
        return cell
    }
    let cell2 = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "cell2")
    cell2.textLabel?.text = String(fullNameArrDorit[indexPath.row])
    return cell2
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 类型的viewcontroller不符合协议uitableviewdatasource - type viewcontroller does not conform to protocol uitableviewdatasource 类型“ ViewController”不符合协议“ UITableViewDataSource” - Type “ViewController” does not conform to protocol 'UITableViewDataSource" 类型“ViewController”不符合协议“UITableViewDataSource” - Type 'ViewController' does not conform to protocol 'UITableViewDataSource' 类型“ ViewController”不符合协议“ UITableViewDataSource” - Type'ViewController' does not conform to protocol 'UITableViewDataSource' 类型“ ViewController”不符合协议“ UITableViewDataSource” - Type 'ViewController' does not conform to protocol 'UITableViewDataSource' Xcode类型“ ViewController”中出现错误不符合协议“ UITableViewDataSource” - Getting error in Xcode type “ViewController” does not conform to protocol“UITableViewDataSource” 与“类型'ViewController'不符合协议'UITableViewDataSource'”相关的编译和构建错误 - Compile & Build error related to “Type 'ViewController' does not conform to protocol 'UITableViewDataSource'” ImagesTabViewController'不符合协议'UITableViewDataSource' - ImagesTabViewController' does not conform to protocol 'UITableViewDataSource' 视图控制器是否符合协议“UITableViewDataSource, Video Mode Delegate”? - viewcontroller conform to protocol "UITableViewDataSource, Video Mode Delegate"? ViewController不确认协议UITableViewDataSource - ViewController does not confirm to protocol UITableViewDataSource
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM