iPhone string comparison strange issue in iOS 6

守給你的承諾、 提交于 2019-12-04 18:42:52

If myTextfield.text is nil, [myTextfield.text isEqualToString: @""] will fail because messaging nil returns nil (or 0, NO as appropriate).

In the second case you have, you are checking for == 0, so even if the string is nil you will still get a positive result.

Lyndsey Scott

In iOS7, untouched UITextFields return nil, whereas in previous iOS versions they return an empty string. Touched UITextFields in both cases should return an empty string.

(Did you ask the question in reverse mistaking iOS6 w 7? If not, I'd also make sure the text field is hooked up properly since a touched iOS7 text field could return an empty string while an unsynthesized iOS6 text field could return NULL since iOS6 is especially strict in this way.)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!