我正在尝试完成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 :(得分:1)
您必须告诉编译器您的单元格属于UITableViewCell
类,这意味着使用!
标记进行向下转换:
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! UITableViewCell