2014-11-25 5 views
0

Я хочу сделать вид таблицы в быстры, и я получаю следующую ошибкуНе соответствует протоколу UITableViewDataSource

«не соответствует к UITableViewDataSource протокола»

Может ли подскажите, где я ошибаюсь?

import UIKit 

class WalkthroughScreen2ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate{ 

    let cityArray = ["Portland","San Francisco","Cupertino"] 
    override func viewDidLoad() { 
     super.viewDidLoad() 
     self.createReminderLabel() 



     // Create our UITableView with our view's frame 
     var tableView: UITableView = UITableView(frame: self.view.frame) 


     // Register our cell's class for cell reuse 
     tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "Cell") 

     // Set our source and add the tableview to the view 
     tableView.dataSource = self 
     self.view.addSubview(tableView) 
    } 



    override func didReceiveMemoryWarning() { 
     super.didReceiveMemoryWarning() 
     // Dispose of any resources that can be recreated. 
    } 
    func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int { 
     return cityArray.count 
    } 


    func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! { 
     // dequeue a cell for the given indexPath 
     var cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCell 

     // set the cell's text with the new string formatting 
     cell.textLabel.text = "\(cityArray[indexPath.row])" 

     return cell 
    } 
} 

ответ

0

Сигнатура cellForRowAtIndexPath неверно в вашем коде, оно должно быть:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell 

разница в том, что tableView не является обязательным. Кроме того, вы должны реализовать этот метод:

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int 

Аналогично, numberOfRowsInSection подпись:

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int 
Смежные вопросы