vee
vee

Reputation: 739

iOS swift 3 coding tableview edit button using UIButton instead of UIBarButton

I wrote the following code. I'm trying to make it so that it functions like act like UIBarButtonItem edit item function, but using a UIButton instead because I have a custom navigation bar, but I'm having several compiling errors. The function is supposed to allow editing when the button is pressed and finish editing when pressed again.

@IBAction func edit(sender: UIButton){
    if [tableView.isEditing] == YES {
        [self.tableView .setEditing(false, animated: false)]
    }
    else{
        [self.tableView .setEditing(true, animated: true)]
    }
}

Upvotes: 1

Views: 424

Answers (1)

Sealos
Sealos

Reputation: 562

You're mixing up Swift and Objective-C code, should look something like this

@IBAction func edit(sender: UIButton) {
    if tableView.isEditing {
        tableView.setEditing(false, animated: false)
    } else{
        tableView.setEditing(true, animated: true)
    }
}

Upvotes: 1

Related Questions