PDA

View Full Version : UITextField.text property clear with nil?




nashyo
Feb 10, 2012, 08:29 AM
Hi,

For clearing the text property of a UITextField programmatically, is it best to write nameTextField.text = @""; or nameTextField.text = nil; //?

I'm not sure if this is the reason why my app is not working properly. I'm still trying to debug.

I've searched through the apple documentation and other forums, and there doesn't seem to be a straight answer anywhere.

Thanks
Rob



xStep
Feb 10, 2012, 02:23 PM
The documentation says that the text property is a NSString and is nil by default. I have used the empty quote method on NSStrings in UILabels and don't know why it wouldn't work with a UITextField also. So, it seems both methods are fine.

nashyo
Feb 11, 2012, 03:19 AM
The documentation says that the text property is a NSString and is nil by default. I have used the empty quote method on NSStrings in UILabels and don't know why it wouldn't work with a UITextField also. So, it seems both methods are fine.

Thanks for this.

I don't have a problem with UILabels either. It's only the UITextFields that seem to cause a problem. I'll look into it.