还是新的iPhone的SDK但是我至今爱它...的UITextField - 如果声明
我只是通过一个过程goign,在线教程和一点点困惑,我想主要有一个的UITextField和一个提交按钮(又名:GO键盘上的操作按钮)
.h文件..
IBOutlet UITextField *InsertUITextFieldBox; // UITextField to input keystrokes..
IBOutlet UILabel *myLabel; // UILabel to show if answer is correct or incorrect..
}
-(IBAction)dropMyKeyboard; // Setup to Say go - and IB - DidEndonExit on my UITextField
我.m文件
-(IBAction)dropMyKeyboard{
NSString *TypedinbyUser = [[NSString alloc] initWithFormat:@"%@", [InsertUITextFieldBox text]]; //saves data in uitextfield to a nsstring
NSString *CorrectAnswer = [[NSString alloc] initWithString:@"http://google.com"]; //answer to used to compare in if statement with uitextfield
[myLabel setText:TypedinbyUser]; // show what was typed in my user
//if statement, if what user types is correct to the CorrectAnswer, then display the following if right or wrong....
if (TypedinbyUser == CorrectAnswer) {
[myLabel setText:@"You Answered Correctly"];
}
[myLabel setText:@"You Answered Incorrectly"];
}
因此,当我运行此操作时,在我的文本框中输入“http://google.com”并按GO键 - 当我知道我输入的内容时,我的UILabel会转到“您的答案不正确”并从我的代码粘贴,没有引号,也手动键入它,并试图在前后添加空格...
任何帮助将是伟大的,因为我在做什么错了..谢谢
最初用compareNoCase写了这个答案:在标准库中没有这个答案,我扩展了NSString类来使用这个方法,并且一直在使用它,所以很久以前忘记了它不是标准的,如果你想做无情的比较尝试caseInsensitiveCompare:代替。 –
或'[TypedinByUser isEqualToString:CorrectAnswer]'。只是品味的问题。 – 2011-08-02 23:14:06
在这种情况下,isEqualToString可能稍微更高效。 –