[英]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.我试图在我的自定义 UIViewController 上实现属性观察器,但我注意到它不适用于 isEditing 属性。
Do you guys have an idea why?你们知道为什么吗?
class MasterViewController: UIViewController {
// MARK: - Properties
override var isEditing: Bool {
didSet {
print("VC is editing")
}
}
}
According to the documentation for isEditing
根据
isEditing
的文档
Use the setEditing(_:animated:) method as an action method to animate the transition of this state if the view is already displayed.
如果已显示视图,请使用setEditing(_:animated :)方法作为操作方法来动画化此状态的过渡。
And from setEditing(_:animated:)
并从
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.
如果isEditing为true,则使用edit-done按钮的子类必须重写此方法,以将其视图更改为可编辑状态;如果为false,则将其视图更改为不可编辑状态。 This method should invoke super's implementation before updating its view.
此方法应在更新其视图之前调用super的实现。
TL;DR TL; DR
You'll want to override setEditing(_:animated:)
instead. 您将要改写
setEditing(_:animated:)
。
It's for those who can't find any example how setEditing works.它适用于那些无法找到 setEditing 工作原理示例的人。
SWIFT 5:
SWIFT 5:
override func setEditing(_ editing: Bool, animated: Bool) {
if yourTableView.isEditing == true {
yourTableView.isEditing = false //change back
} else {
yourTableView.isEditing = true // activate editing
editButtonItem.isSelected = true // select edit button
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.