【发布时间】:2016-07-28 10:50:09
【问题描述】:
我使用 Swift 创建了一个滑出式菜单。我以前做过很多次,但是当我今天创建它时,我得到了这个错误(见截图)。这可能只是我犯的一个简单的错误。
这是我认为导致问题的代码:
override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
var cell:UITableViewCell? = tableView.dequeueReusableCellWithIdentifier("Cell")! as UITableViewCell
if cell == nil{
cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "Cell")
cell!.backgroundColor = UIColor.clearColor()
cell!.textLabel!.textColor = UIColor.darkTextColor()
let selectedView:UIView = UIView(frame: CGRect(x: 0, y: 0, width: cell!.frame.size.width, height: cell!.frame.size.height))
selectedView.backgroundColor = UIColor.blackColor().colorWithAlphaComponent(0.3)
cell!.selectedBackgroundView = selectedView
}
cell!.textLabel!.text = tableData[indexPath.row]
return cell
}
截图:
更新:我已尝试删除 override
希望有人能帮忙!
【问题讨论】:
-
@RDC 感谢您的建议,但没有奏效。查看更新
-
您是否真的实现了
UITableView代表所需的协议?class YourViewController: UIViewController, UITableViewDataSource, UITableViewDelegate { /* ... */ } -
我可能是错的,但只是为了完整起见......你是继承
UIViewController还是UITableViewController?如果是第二个,是否配置了静态单元格?
标签: ios swift uitableview superclass