2014-12-22 18 views
0

我得到的错误一样敏捷的dynamic_cast类无条件用于以下,错误定制TableViewCell:迅速的dynamic_cast类无条件

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
     var cell :CustomTableViewCell = tableView.dequeueReusableCellWithIdentifier("cell") as CustomTableViewCell; // error here 

     return cell 
    } 

请帮我解决这个问题。 谢谢!

+0

删除分号,并尝试 – karthikeyan

+0

那力的工作!感谢您的回复 – rishu1992

回答

0

我找到了答案。下面以在viewDidLoad方法中添加命令,你应该在最后你的错误行与您的自定义单元格类注册

self.tableView.registerClass(CustomTableViewCell.self, forCellReuseIdentifier: "cell") 
0

dequeueReusableCellWithIdentifier()正在返回类型AnyObject的可选项。所以强制型铸造可能会造成问题。如果您使用as?类型铸造将工作我猜

var cell :CustomTableViewCell = tableView.dequeueReusableCellWithIdentifier("cell") as? CustomTableViewCell; 

    // cell will not be nil if you registered already. Bt this if check may be needed to supress the warning of optional use 
    if let _cell = cell{ 

    } 
+0

谢谢!但是,它显示错误!要求添加'!'代替 '?' 。达不工作:-( – rishu1992

+0

你可以尝试像'var cell:CustomTableViewCell?= tableView.dequeueReusableCellWithIdentifier(“cell”)as?CustomTableViewCell' –