Reputation: 3634
I've dropped a UITextField control on one of my xibs and I want it to be un-editable. I've "unchecked" both the "enabled" and "User Interaction Enabled" on the "Attributes Inspector." However, when I run this application in the simulator, when I tap on the TextField the keyboard always appears. I've searched around and these two attributes seem to be what controls the "edit-ness" of this particular control. I'm able to create an UITextArea, as there exists an "Editable" checkbox that I "unchecked." However, there is no "Editable" checkbox in the inspector for a UITextField. Am I out of luck? Or is there more setup required that I'm not aware of?
Upvotes: 1
Views: 1109
Reputation: 1328
Try with this:
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
return NO;
}
Upvotes: 1
Reputation: 3634
After pulling my hair out due to none of the solutions working (checkboxes and adding code to disable the TextField), what finally solved the problem was deleting the control, and then re-adding it. Once it was re-added, I was able to disable the TextField with either the "Enabled" checkbox or assigning "NO" to textField.enabled. I have no idea why it works now, but this can be a solution to others that are having the same problem.
Upvotes: 0
Reputation: 1034
yourTextFieldName.enabled = NO;
This seems to work pretty well for me, hope this helps.
Upvotes: 0
Reputation: 5940
Try this, in your viewDidLoad set your textField to this:
myTextField.userInteractionEnabled = FALSE;
Upvotes: 0
Reputation: 3998
The "Enabled" property is the one you're looking for if you want to disable touch events from the user.
It's possible you're having some trouble with the linkage between your Interface Builder and your app (I've had this problem several times).
Try setting the value directly in your code instead of using the IB and see if it gives you the desired results.
Upvotes: 0