1
votes

I am following this tutorial http://www.raywenderlich.com/62435/make-swipeable-table-view-cell-actions-without-going-nuts-scroll-views to create a customized table cell. But I am using swift instead of objective c.

Here is my table cell view in 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)
    }
}

But it does not compile, I get error saying :

MyTableViewCell.swift:38:9: Property 'self.delegate' not initialized at super.init call

And if I get rid of "init(coder aDecoder: NSCoder)", I get error saying 'required' initializer 'init(coder:)' must be provided by subclass of UITableViewCell'.

I have read this thread Class does not implement its superclass's required members

about what to do in my required init(coder aDecoder: NSCoder).

But I can't get the code to compile.

I appreciate if someone can help me.

Thank you.

1

1 Answers

3
votes

It's saying you need to have delegate defined at the end of all init methods, because that class variable is not set as an optional. One approach would be to make it optional (meaning it can be nil)

var delegate: SwipeableCellDelegate?

Read about initialization and Optional Property Types here