Swift:表视图超类错误 [英] Swift: Table view superclass error
本文介绍了Swift:表视图超类错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经使用Swift创建了一个滑出菜单.我之前已经做过很多次,但是今天创建它时,出现此错误(请参见屏幕截图).这可能只是我犯的一个简单错误.
I have created a slide out menu using Swift. I have done this many times before, but when I created it today, I get this error (see screenshot). It could just be a simple mistake I have made.
以下是我认为引起问题的代码:
Here is the code, that I think is causing the problem:
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
希望有人可以提供帮助!
Hope someone can help!
推荐答案
该方法不会覆盖超类的任何方法,因为签名错误.
The method does not override any method of the superclass because the signature is wrong.
正确的签名是
override func tableView(tableView: UITableView,
cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
所有参数均为非可选类型.
All parameters are non-optional types.
并使用推荐的方法
let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier,
forIndexPath: indexPath)
也总是返回非可选类型
这篇关于Swift:表视图超类错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文