Ios 如何为自定义UITableViewCell类设置初始值设定项?

Ios 如何为自定义UITableViewCell类设置初始值设定项?,ios,uitableview,swift,initialization,init,Ios,Uitableview,Swift,Initialization,Init,我已经到处寻找这个问题的答案,但每个解决方案都会带来新的编译器错误 如何为从UITableViewCell继承的类设置初始值设定项? 这就是我目前所拥有的,我们将非常感谢您的帮助: 设置单元格。swift class SettingCell: UITableViewCell { @IBOutlet weak var settingsLabel: UILabel! @IBOutlet weak var settingsSwitch: UISwitch? @IBOutlet

我已经到处寻找这个问题的答案,但每个解决方案都会带来新的编译器错误

如何为从UITableViewCell继承的类设置初始值设定项?

这就是我目前所拥有的,我们将非常感谢您的帮助:

设置单元格。swift

class SettingCell: UITableViewCell {

    @IBOutlet weak var settingsLabel: UILabel!
    @IBOutlet weak var settingsSwitch: UISwitch?
    @IBOutlet weak var timeSetting: UILabel?

    var cellDelegate: SettingCellDelegate?

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

    init(settingLabel: UILabel!, settingSwitch: UISwitch?, timeSetting: UILabel?) {

        super.init(style: UITableViewCellStyle, reuseIdentifier: String?)
        self.settingsLabel = settingLabel
        self.settingsSwitch = settingSwitch
        self.timeSetting = timeSetting

    }

    required init(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    @IBAction func handledSwitchChange(sender: UISwitch) {

        self.cellDelegate?.didChangeSwitchState(sender: self, isOn:settingsSwitch!.on)


    }
   ...

}
修复错误:

'UITableViewCellStyle.Type' is not convertible to 'UITableViewCellStyle'

编译器错误:

'UITableViewCellStyle.Type' is not convertible to 'UITableViewCellStyle'

当你打这个电话时:

super.init(style: UITableViewCellStyle, reuseIdentifier: String?)
您需要提供实际的单元样式和实际的重用标识符。您现在编写的代码就好像这一行是函数定义,而不是函数调用

将其更改为:

super.init(style: .Default, reuseIdentifier: "SettingCell")

(尽管最好至少重用标识符应该由调用方提供,而不是静态地提供)

感谢wain的响应,这里是编译器在我使用您的签名时返回的错误:“UITableViewCellStyle.Type”没有名为“UITableViewCellStyleDefault”的成员好的,刚刚将其更改为:super.init(样式:。默认,reuseIdentifier:“SettingCell”)对不起,这是枚举的obj-c版本