2015-10-31 5 views
1

dequeReusableCellWithIdentifier ожидает строку в качестве параметра. Но, когда я передаю строку, она показывает ошибку.Ячейка Tableview в swift

Код:

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

var cell = tableView.dequeueReusableCellWithIdentifier("CELL") as? UITableViewCell 

if cell == nil { 
cell = UITableViewCell(style: UITableViewCellStyle.Value1, reuseIdentifier: "CELL") 
} 

    //we know that cell is not empty now so we use ! to force unwrapping 

cell!.textLabel.text = "abc" 
cell!.detailTextLabel.text = "1/2" 


return cell } 

Проблема:

Downcast от UITableViewCell? в UITableViewCell только разворачиваются параметры.

+0

Вы можете сообщить об ошибке? – sasquatch

ответ

0

Возвращаемое значение dequeueReusableCellWithIdentifier объявлено как UITableViewCell?, поэтому просто удалите литье.

var cell = tableView.dequeueReusableCellWithIdentifier("CELL") 

Это всегда полезно использовать Быстрая помощь или -Нажмите на символ для поиска объявления.

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