Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i identify self.editButtonItem button's clicked event?

I set my left bar button of UINavigationController as edit button using the code

leftBarButton = self.editButtonItem;

I want to change some disable/enable properties of other buttons with respect to the edit button's click action.

How can i find whether the Edit button is pressed or not?

like image 625
Confused Avatar asked Sep 07 '11 12:09

Confused


4 Answers

The edit button's action sends your view controller the setEditing:animated message. Override this in your subclass to perform other actions when entering or leaving edit mode.

Be sure to call the super implementation at the end to manage the rest of the transition to editing view.

like image 175
jrturton Avatar answered Oct 16 '22 22:10

jrturton


So finally i got the solution...

-(void)setEditing:(BOOL)editing animated:(BOOL)animated {

    [super setEditing:editing animated:animated];

    if(editing) {
        //Do something for edit mode
    }

    else {
        //Do something for non-edit mode
    }

}

This method will be called with out changing the original behavior of self.editButtonItem button.

like image 45
Confused Avatar answered Oct 16 '22 22:10

Confused


In Swift:

@IBOutlet weak var tableView: UITableView!

override func viewDidLoad() {
    super.viewDidLoad()

   ....
    self.navigationItem.leftBarButtonItem = self.editButtonItem()
}

override func setEditing(editing: Bool, animated: Bool) {
    // Toggles the edit button state
    super.setEditing(editing, animated: animated)
    // Toggles the actual editing actions appearing on a table view
    tableView.setEditing(editing, animated: true)
}
like image 7
ginchly Avatar answered Oct 16 '22 22:10

ginchly


In Swift you can follow the below methods:

  @IBOutlet weak var tableView: UITableView!

    override func viewDidLoad() {
        super.viewDidLoad()
        navigationItem.rightBarButtonItem = editButtonItem()
    }

   override func setEditing(editing: Bool, animated: Bool){

        super.setEditing(editing, animated: animated)
        tableView.setEditing(editing, animated: true)


    }
like image 3
Nischal Hada Avatar answered Oct 16 '22 22:10

Nischal Hada