2015-04-12 154 views
1

我已经搜索了周围的答案,但每个解决方案都会带来新的编译器错误。如何为自定义UITableViewCell类设置初始值设定项?

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

这是我到目前为止,任何帮助,将不胜感激:

SettingCell.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) 


    } 
    ... 

} 

修正 - It错误:

enter image description here

编译器错误:

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

回答

2

当你调用这一行:

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

您需要提供一个实际的单元格样式和实际重用标识符。您此刻的代码被写入,就好像这行代码是函数定义,而不是函数调用。

改变它的东西,如:

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

为响应韦恩(尽管优选至少重用标识符应该由调用者提供的,不是静态)

+0

感谢,这里的错误,编译器当我使用你的签名时返回:'UITableViewCellStyle.Type'没有一个成员'UITableViewCellStyleDefault' –

+1

好吧,得到它只是改变它:super.init(style:.Default,reuseIdentifier:“SettingCell”) –

+1

对不起,是enum – Wain

相关问题