2016-05-18 7 views
0

以下のコードをご覧ください。エラー "タイプViewControllerがプロトコル 'UITableViewDataSource'に準拠していません。私はこのエラーを調査し、他の答えは、UITableViewDataSourceは特定の関数が必要だと言うが、私はそれらの関数を含めている。他に何が間違っているのでしょうか?私はXcode 7.3を使用しています。必要な機能を持っていても「タイプViewControllerはプロトコル 'UITableViewDataSource ...」に準拠していません

import UIKit 

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { 

    @IBOutlet weak var zipCodeText: UITextField! 
    @IBOutlet weak var zipTable: UITableView! 

    var zipArray: [String] = [] 


    override func viewDidLoad() { 
     super.viewDidLoad() 
     self.zipTable.delegate = self 
     self.zipTable.dataSource = self 
    } 

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

    @IBAction func addZipButton(sender: UIButton) { 
     zipArray.append(zipCodeText.text!) 
     zipTable.beginUpdates() 
     zipTable.insertRowsAtIndexPaths([ 
      NSIndexPath(forRow: zipArray.count-1, inSection: 0) 
      ], withRowAnimation: .Automatic) 
     zipTable.endUpdates() 
    } 

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

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) { 
     let cell:UITableViewCell = tableView.dequeueReusableCellWithIdentifier("cell")! 
     cell.textLabel?.text = zipCodeText.text 
    } 

} 

答えて

3

tableView(_:cellForRowAtIndexPath:)にセルが返されていません。

このような何か試してみてください:私がいることを、私は元のエラーを持っているし、今 "と言う1ないとき

+0

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableViewDataSource_Protocol/#//apple_ref/occ/intfm/UITableViewDataSource/tableView:cellForRowAtIndexPath:あなたは、戻り値に関する情報が表示されますドキュメントで

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell:UITableViewCell = tableView.dequeueReusableCellWithIdentifier("cell")! cell.textLabel?.text = zipCodeText.text // Make sure to include the return statement return cell } 

を戻り値のセルライン上の「void関数の予期しない非void戻り値」を参照してください。 – Impulso

+0

申し訳ありませんが、返品のタイプも忘れてしまいました。関数ヘッダーに ' - > UITableViewCell'を追加してください。 – grez

+0

これはエラーを取り除いたものです。ありがとう! – Impulso

関連する問題