2
我得到的編碼時的錯誤,說類型「視圖控制器」不符合協議「UITableViewDataSource」
類型‘視圖控制器’不符合協議‘UITableViewDataSource’
任何人都可以告訴了什麼錯這個
import UIKit
class ViewController: UIViewController, UITableViewDataSource{
let devCourses = [
("Math"),
("Science"),
("English"),
("Computer Programming"),
("Physics")]
func numberOfSectionsInTableview(tableview: UITableView)-> Int {
return 1
}
func tableview(tableView: UITableView, numberOfRowsInSection section: Int) ->Int{
return devCourses.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = UITableViewCell()
let (courseTitle) = devCourses[indexPath.row]
cell.textLabel?.text = courseTitle
return cell
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
您是否嘗試將父級更改爲UITableViewController? –
[類型「ViewController」可能重複不符合協議「UITableViewDataSource」](https://stackoverflow.com/questions/28241279/type-viewcontroller-does-not-conform-to-protocol-uitableviewdatasource) – SmokeDispenser
我把「tableview」而不是「tableView」,這就是爲什麼我犯了錯誤。感謝球員的幫助! –