Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIViewController isEditing - Property observer doesn't work

I was trying to implement property observers on my custom UIViewController but I noticed it was not working with the isEditing property.

Do you guys have an idea why?

class MasterViewController: UIViewController {

    // MARK: - Properties

    override var isEditing: Bool {
        didSet {
            print("VC is editing")
        }
    }
}
like image 564
Berty86 Avatar asked Jan 29 '23 07:01

Berty86


1 Answers

According to the documentation for isEditing

Use the setEditing(_:animated:) method as an action method to animate the transition of this state if the view is already displayed.

And from setEditing(_:animated:)

Subclasses that use an edit-done button must override this method to change their view to an editable state if isEditing is true and a non-editable state if it is false. This method should invoke super’s implementation before updating its view.


TL;DR

You'll want to override setEditing(_:animated:) instead.

like image 61
Craig Siemens Avatar answered Feb 12 '23 13:02

Craig Siemens