0
我試圖建立我的表視圖,我使用不符合協議'UITableViewDataSource'錯誤?
class ExerciseDatabaseController: UIViewController, UITableViewDataSource, UITableViewDelegate {
然後我使用的強制性功能:
func ExerciseDatabaseController(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath as IndexPath)
return cell
}
和
func ExerciseDatabaseController(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 0
}
按照蘋果的指導方針:https://developer.apple.com/reference/uikit/uitableviewdatasource
我無法解決爲什麼我這個班級仍然存在不符合協議的錯誤?
類型「ExerciseDatabaseController」不符合協議「UITableViewDataSource」
爲什麼你預先給你的班級名稱給他們呢?你正在創造新的方法,看起來像協議搜索的那些,但它們不是。 – ohr
對不起,這是我第一次做這個,所以很可能犯了愚蠢的錯誤,錯誤是給予函數前類名的功能?我一定誤解了教程! – infernouk
只需查看「UITableViewDelegate」和「UITableViewDataSource」的文檔即可正確聲明這些函數。 – rmaddy