2016-06-30 9 views
1

最近問題が発生しました。ViewControllerがプロトコルUITableViewDataSourceに準拠していません

enter image description here

私もいくつかのコードを投稿します。インターネットからの方法を試しましたが、成功しませんでした。また、2つのテーブルをView Controllerにリンクしました。ここで

enter image description here

いくつかのコードです。

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 
    } 

} 

また、他のすべての機能を追加しようとしましたが、問題は解決しませんでした。私は何か悪いことをリンクしていると思う、私は知らない。

+0

がテーブルビューにすべてのtableview2を置き換え、あなたは –

答えて

2

tableView2をすべてtableViewに置き換え、それぞれの方法を1つだけ残してください。すべてのUITableViewインスタンスに対して同じデリゲートメソッドが必要です。最初のパラメータとUITableViewプロパティを比較することで、このメソッド内の異なるインスタンスを分離できます。また、切断法の番号を追加します。

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 
} 
+1

が自分の前にいることをしようとしたが、それは私が行った理由です、働いていなかった、同じデータ・ソースとデリゲートメソッドでは、タグによるテーブルビューを識別することができますtableViewおよびtableView2関数用。私が間違っていたものの、あなたのコードは私のプロジェクトで完璧に動作し、私のプロジェクトを解決しました。 –

関連する問題