Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set UITextField as non editable - Objective C

    [Number.editable = NO];
    [Number resignFirstResponder];
    [Password.editable = NO];
    [Password resignFirstResponder];

I am getting the error

Request for member 'editable' in something not a structure or union

:S

Thanks

like image 598
user393273 Avatar asked Jul 18 '10 10:07

user393273


3 Answers

Firstly, the [...] aren't needed if you're not sending a message.

Number.editable = NO;
[Number resignFirstResponder];
Password.editable = NO;
[Password resignFirstResponder];

But this is not the cause of error. The .editable property is only defined for UITextView, not UITextField. You should set the .enabled property for a UITextField (note that a UITextField is a UIControl).

Number.enabled = NO;
...
like image 121
kennytm Avatar answered Nov 05 '22 03:11

kennytm


Also, you can use the delegate methods.

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
  return NO;
}

That would do the trick, I prefer this method over setting textField.enabled = YES when it's likely that the ability to edit will change during the lifecycle of the app.

like image 35
makdad Avatar answered Nov 05 '22 04:11

makdad


textField.userInteractionEnabled = NO;

Hope this helps..

like image 6
Henit Nathwani Avatar answered Nov 05 '22 02:11

Henit Nathwani