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
}
}
: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableViewDataSource_Protocol/#//apple_ref/occ/intfm/UITableViewDataSource/tableView:cellForRowAtIndexPath:あなたは、戻り値に関する情報が表示されますドキュメントで
を戻り値のセルライン上の「void関数の予期しない非void戻り値」を参照してください。 – Impulso
申し訳ありませんが、返品のタイプも忘れてしまいました。関数ヘッダーに ' - > UITableViewCell'を追加してください。 – grez
これはエラーを取り除いたものです。ありがとう! – Impulso