我几个小时前才开始玩弄 XCode,正在学习 HelloWorld 教程。 当用户单击返回按钮时,我设法关闭了键盘窗口。
但是,我的按钮应该具有与“返回”按钮完全相同的行为。它现在做同样的事情,它只是在提交时不关闭键盘。我该怎么做?
- (IBAction)button:(id)sender {
[self changeLabelWithText: self.textField.text];
}
- (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
if (theTextField == self.textField) {
[theTextField resignFirstResponder];
[self changeLabelWithText: self.label.text];
}
return YES;
}
- (void)changeLabelWithText: (NSString *) text {
self.label.text = [NSString stringWithFormat:@"Hej, %@", text];
}
最佳答案
或者您可以这样做(这样您就不必关心它是哪个文本字段/ View )。
[self.view endEditing:YES];
关于objective-c - XCode - 单击按钮关闭键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13970970/