开发者

Getting text from UITextField

开发者 https://www.devze.com 2023-03-20 20:44 出处:网络
I\'m trying to see if what the user enters in a text field is equal to a string. For some reason, my app does not listen t开发者_Python百科o:

I'm trying to see if what the user enters in a text field is equal to a string. For some reason, my app does not listen t开发者_Python百科o:

[textField1.text isEqualToString:@"Blah"];

It also doesn't work with:

[textField1 text] isEqualToString:@"Blah";

It doesn't seem to respond to text. Yet, when I simply connect textField1 to a text view everything works beautifully! What am I doing wrong? Thanks for your help!


I would suggest logging what you get from textField1.text. If the returned string is nil while there is text in the text field, then that means that your outlets haven't been connected properly. It's also important to realize that -isEqualToString looks for an exact match (case, whitespace, all of it) so even an extra space would cause it to return NO.


if ([textField1.text compare:@"Blah"] ==0) {
//its a match

}
0

精彩评论

暂无评论...
验证码 换一张
取 消