Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which is better, setEnabled or setUserInteractionEnabled?

I want to make a UIButton disable for user touch. Both setEnabled and setUserInteractionEnabled can do this. Which is better? How are they different?

like image 266
Yi Jiang Avatar asked Mar 26 '13 23:03

Yi Jiang


People also ask

What is the difference between setenabled and setdisabled in JavaScript?

As setEnabled and setDisabled are not virtual, you're not reimplementing them but hiding them. There is no separate disabled property. setDisabled is just a convenience slot to enable a signal with a boolean value to either enable or disable on true.

What is the difference between setenabled and setdisabled in qwidget?

As setEnabled and setDisabled are not virtual, you're not reimplementing them but hiding them. There is no separate disabled property. setDisabled is just a convenience slot to enable a signal with a boolean value to either enable or disable on true. Lets look at the implementation of setDisabled in QWidget for reference: /*! enables input events.

Is it possible to re-implement setenabled and setdisabled?

Could be yes, If you are toying with the enabled/disabled state of the children widget it can quickly get messy I think your problem is a different one. As setEnabled and setDisabled are not virtual, you're not reimplementing them but hiding them.


1 Answers

enabled is a property of UIControl, which is the superclass for UIButton. userInteractionEnabled is a property of UIView (which is the superclass of UIControl). enabled has effects on the visual state of the object (grayed out, by default) and is generally the preferred method of disabling a control—visual feedback indicating behaviors is a good thing.

There's not much practical upshot beyond that. Code that interacts with your controls is more likely to check if buttons are enabled than if their userInteractionEnabled property is set. Hence using enabled is more conventional.

like image 94
Seamus Campbell Avatar answered Nov 08 '22 20:11

Seamus Campbell