12
    [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

4 Answers 4

28

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;
...
1
  • i realised this and changed just after posting but that is still not working :S
    – user393273
    Commented Jul 18, 2010 at 10:17
18

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.

1
  • The BlocksKit pod makes this even easier: list.bk_shouldBeginEditingBlock = ^BOOL (UITextField *field) { return NO; }; Commented Apr 12, 2015 at 14:51
6
textField.userInteractionEnabled = NO;

Hope this helps..

1
  • Note that this will mean that the user will not be able to do long press to copy also
    – mylogon
    Commented Jan 24, 2017 at 2:58
0

Returning NO from shouldChangeCharactersInRange would be better choice because if text is longer than the textfield width, then above solution will give problem, because user won't be able to see all text(i.e. text hidden beyond the text field width)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.