2015-05-11 28 views
1

我想完成一个UITableView,我在一行代码的最后部分收到错误。完成一个UITableView

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
var cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as UITableViewCell 

//ERROR IS IN THE LINE ABOVE ("anyobject" is not convertible to "UItableViewCell" 

if (indexPath.section == 1) { 
let (unit, availability) = myUnits[indexPath.row] 
cell.textLabel?.text = unit 
cell.detailTextLabel?.text = availability 
} else { 
let (assessment, mark) = myAssessments[indexPath.row] 
cell.textLabel?.text = assessment 
cell.detailTextLabel?.text = mark 

} 
return cell 
} 
+0

你缺少as'后'一个感叹号。投票结束为错字。 – dasblinkenlight

回答

1

你必须告诉编译器,你的细胞是UITableViewCell类的,这意味着使用!马克向下转换:

let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! UITableViewCell 
+0

谢谢,加入后!我可以成功运行,但不会打开表格视图。然后它转到代码 @UIApplicationMain class AppDelegate:UIResponder,UIApplicationDelegate {0} {0} {}} {} {}},并且绿线表示线程1:信号SIGABRT。我相信它将代理和数据源连接到视图控制器 – HelpSwiftXcode

+0

您能否从调试器控制台提供日志? –

+0

运行后没有任何东西进入调试器控制台。当我点击下一页去tableview它然后去网络线程1然后12主,并显示代码,这是突出绿色我说上面。你知道这可能是什么吗? – HelpSwiftXcode