2016-01-09 5 views
2

Ошибка 0- Как я могу решить этот вопрос и почему у него есть проблемы?UITableViewCell 'не имеет статуса' dequeueReusableCellWithIdentifier '

class ViewController: UIViewController , UITableViewDataSource { 
     @IBOutlet weak var tableView: UITableViewCell! 
     override func viewDidLoad() { 
      super.viewDidLoad() 
      } 
     override func didReceiveMemoryWarning() { 
      super.didReceiveMemoryWarning() 
     } 

     func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int{ 
      return 20 
     } 
     func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
      let cell = self.tableView.dequeueReusableCellWithIdentifier("todoCell") as! UITableViewCell 
      return cell 
     } 
     } 
+0

В сообщении об ошибке сообщается, что 'self.tableview' возвращает объект' UITableViewCell' и что 'UITableViewCell' не имеет члена' dequeueReusableCellWithIdentifier'. – Blackwood

ответ

6

Ваш tableView выходе ошибочно объявлен как UITableViewCell вместо UITableView.

@IBOutlet weak var tableView: UITableView! 

BTW - внутри различных методов источника данных и делегата, используйте параметр tableView вместо доступа к свойству.

Пример:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
    let cell = tableView.dequeueReusableCellWithIdentifier("todoCell") as! UITableViewCell 
    return cell 
} 
0

Я имел эту проблему, пока я не понял, что этот синтаксис изменился swift3

swift3:

пусть клетка = tableView.dequeueReusableCell (withIdentifier: cellReuseIdentifier, для : indexPath) как! CustomTableViewCell

перед:

пусть клетка = tableView.dequeueReusableCellWithIdentifier (cellReuseIdentifier, forIndexPath: indexPath), как! CustomTableViewCell

Смежные вопросы