gpt4 book ai didi

ios - Swift: TableView 父类(super class)错误

转载 作者:行者123 更新时间:2023-11-30 13:26:23 25 4
gpt4 key购买 nike

我使用 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
}

屏幕截图:

enter image description here

更新:我尝试删除覆盖

enter image description here

希望有人能帮忙!

最佳答案

该方法不会重写父类(super class)的任何方法,因为签名错误。

正确的签名是

override func tableView(tableView: UITableView, 
cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

所有参数都是非可选类型。

并使用推荐的方法

let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier,
forIndexPath: indexPath)

它也始终返回非可选类型

关于ios - Swift: TableView 父类(super class)错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37143682/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com