0

I'm trying to check if a text field is enabled or not in Objective-C on Xcode. (note: enabled is different from not empty)

if([_firstTextField.userInteractionEnabled == NO]){
rmaddy
  • 314,917
  • 42
  • 532
  • 579

2 Answers2

0

UITextField is enabled by default. You can use isEnabled Property :

if(YOUR_TEXT_FIELD.isEnabled) {
} 

And further to disable:

YOUR_TEXT_FIELD.enabled = NO;

Update:

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 (greyed out, by default) and is generally the preferred method of disabling a control—visual feedback indicating behaviours 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; it's more conventional.

REFERENCE

Anurag Sharma
  • 4,276
  • 2
  • 28
  • 44
0

The code I used was right, i just needed to remove the Square Brackets!

if(_firstTextField.userInteractionEnabled == NO)

ROOKIE MISTAKE.