gpt4 book ai didi

swift - UITableViewCell的编辑样式

转载 作者:行者123 更新时间:2023-11-30 10:21:17 25 4
gpt4 key购买 nike

我想向 MyTableView.swift 文件添加一个新函数,但出现错误:

Overriding method with selector 'initWithStyle: reuseIdentifier:' has incompatible type '(UITableViewCellStyle, String) -> MyTableViewCell'

这是我想添加的代码:

init(style: UITableViewCellStyle, reuseIdentifier: String) {
super.init(style: UITableViewCellStyle.Subtitle, reuseIdentifier: reuseIdentifier)
}

整个代码MyTableView.swift文件:

import UIKit

class MyTableViewCell: UITableViewCell {

let medColor: UIColor = UIColor(red: 0.973, green: 0.388, blue: 0.173, alpha: 1)

init(style: UITableViewCellStyle, reuseIdentifier: String) {
super.init(style: UITableViewCellStyle.Subtitle, reuseIdentifier: reuseIdentifier)
}

override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}

override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)

// Configure the view for the selected state
}
}

最佳答案

它说 (UITableViewCellStyle, String) 类型不等于 (UITableViewCellStyle, String?)
如果你看一下 UItableViewCell 的 init 方法,它看起来像这样 -
init(样式:UITableViewCellStyle,reuseIdentifier:字符串?)

修复
String的reuseIdentifier类型更改为可选字符串String?

 override init(style: UITableViewCellStyle, reuseIdentifier: String?){
super.init(style: UITableViewCellStyle.Subtitle, reuseIdentifier: reuseIdentifier)
}

关于swift - UITableViewCell的编辑样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26425965/

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