2016-11-07 105 views
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」

+1

爲什麼你預先給你的班級名稱給他們呢?你正在創造新的方法,看起來像協議搜索的那些,但它們不是。 – ohr

+0

對不起,這是我第一次做這個,所以很可能犯了愚蠢的錯誤,錯誤是給予函數前類名的功能?我一定誤解了教程! – infernouk

+0

只需查看「UITableViewDelegate」和「UITableViewDataSource」的文檔即可正確聲明這些函數。 – rmaddy

回答

0

如果你開始輸入的功能名稱的Xcode會自動完成它們。這是一個例子,你會得到help。 (和文檔中的鏈接)

func numberOfSectionsInTableView(tableView: UITableView) -> Int 
    { 
     return 1 
    } 
+0

感謝這讓我走上了正軌! – infernouk

相關問題