我正在开发iphone应用程序。无法在应用程序运行期间关闭Textfield框
当我的应用程序正在运行(在我的计算机上测试期间)时,我需要更改文本框框中的值,但是当它完成时,键盘仍然保留,我无法回到应用程序,我被困!
如何关闭键盘并继续?
非常感谢
我正在开发iphone应用程序。无法在应用程序运行期间关闭Textfield框
当我的应用程序正在运行(在我的计算机上测试期间)时,我需要更改文本框框中的值,但是当它完成时,键盘仍然保留,我无法回到应用程序,我被困!
如何关闭键盘并继续?
非常感谢
将委托UITextField
,然后实现的UITextField委托方法 这将使用户能够使用键盘返回键隐藏键盘。
-(BOOL) textFieldShouldReturn:(UITextField *)textField{
[textField resignFirstResponder];
return YES;
}
如果您正在使用一个UIButton然后
- (IBAction)hideKeyboard {
[self.view endEditing:YES];
}
如果你想辞职的键盘,当用户触摸屏幕外的UITextField,然后使用下面的代码将在所有的UITextField
工作在UIView
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
for (UIView * txt in self.view.subviews){
if ([txt isKindOfClass:[UITextField class]] && [txt isFirstResponder]) {
[txt resignFirstResponder];
}
}
}
OR
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[self.view endEditing:YES];
}
@ user2971617如果您发现有用的答案,请接受它作为正确的答案,这将有助于从未回答的问题列表中删除此问题。 – icodebuster
请先搜索:http://stackoverflow.com/questions/12227859/hide-keyboard-on-touch-outside-of-textfield – trojanfoe
因为之前曾有人问过:http://stackoverflow.com/问题/ 3338967 /隐藏键盘 - 当uitextfield - 失去重点 – trojanfoe