【发布时间】:2014-11-09 06:21:10
【问题描述】:
我正在按照本教程http://www.raywenderlich.com/62435/make-swipeable-table-view-cell-actions-without-going-nuts-scroll-views 创建自定义表格单元格。但我使用的是swift而不是objective c。
这是我在 swift 中的表格单元格视图。
protocol SwipeableCellDelegate {
func buttonOneActionForItemText(itemText: NSString)
func buttonTwoActionForItemText(itemText: NSString)
}
class MyTableViewCell: UITableViewCell {
@IBOutlet weak var button1: UIButton!
@IBOutlet weak var button2: UIButton!
@IBOutlet weak var mytextLabel: UILabel!
@IBOutlet weak var testLabel: UILabel!
var delegate: SwipeableCellDelegate
init(delegate: SwipeableCellDelegate) {
self.delegate = delegate
super.init()
}
required init(coder aDecoder: NSCoder) {
// fatalError("init(coder:) has not been implemented")
super.init(coder : aDecoder)
}
}
但它无法编译,我收到错误提示:
MyTableViewCell.swift:38:9: 属性 'self.delegate' 未在 super.init 调用时初始化
如果我去掉“init(coder aDecoder: NSCoder)”,我会收到错误提示 'required' 初始化器 'init(coder:)' 必须由 UITableViewCell' 的子类提供。
我已阅读此主题 Class does not implement its superclass's required members
关于在我需要的 init(coder aDecoder: NSCoder) 中做什么。
但我无法编译代码。
如果有人可以帮助我,我将不胜感激。
谢谢。
【问题讨论】: