2016-09-28 138 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. –

相关问题