2016-09-28 135 views
0

我在寫代碼的困難,在協議中存在錯誤,我使用的Xcode 7.3.1 enter image description hereType'ViewController」不符合協議‘UITableViewDataSource’

//2 Method dari protokol UITableViewDataSource->method 1. 
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 

    //Return the numberofRowsInSection. 
    return namaRestoran.count 
} 
//Method 2. 
func tableView(tableView: UITableView, cellForRowAtIndextPath indexPath: NSIndexPath) -> UITableViewCell { 
    let cellIdentifier = "Cell" 
    let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as UITableViewCell 

    //Configurasi the Cell. 
    cell.textLabel?.text = namaRestoran[indexPath.row] 

    return cell 
} 
+0

您需要查看整個錯誤消息;它應該告訴你你沒有實現哪些方法來符合這個協議。 – Kilazur

回答

0

您必須實現的功能:

func numberOfSectionsInTableView(tableView: UITableView) -> Int { 
    return 1; // Or any other number 
} 
+3

這是一個可選項。 –

2

看起來你錯誤地拼寫了tableView(tableView: UITableView, cellForRowAtIndextPath indexPath: NSIndexPath) -> UITableViewCell

它應該是tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell

+0

他是對的。索引後取出T. –

相關問題