Objective c 在xcode脚本中隐藏键盘

Objective c 在xcode脚本中隐藏键盘,objective-c,ios,Objective C,Ios,xcode新手,我正在xcode 4.2中创建一个简单的登录表单,我想隐藏键盘,我有正确的代码,从教程中可以看出,我需要将视图的类更改为UIControl,但没有选项,在使用故事板时,还有其他方法吗 - (IBAction)backGroundTouched:(id)sender { [emailTextField resignFirstResponder]; [passTextField resignFirstResponder]; } 如果您的两个文本字段是某个更高级别视图

xcode新手,我正在xcode 4.2中创建一个简单的登录表单,我想隐藏键盘,我有正确的代码,从教程中可以看出,我需要将视图的类更改为UIControl,但没有选项,在使用故事板时,还有其他方法吗

- (IBAction)backGroundTouched:(id)sender
{
    [emailTextField resignFirstResponder];
    [passTextField resignFirstResponder];
}

如果您的两个文本字段是某个更高级别视图的子视图,您也可以使用
[higherLevelView endEditing]并且不关心当前活动的子视图。

假设您在viewCotroller中执行这些操作,则调用

Make sure your both text fields is connect with it's IBOutlets.
No need to change UIView to UIControl.

// Connect every textfield's "Did end on exit" event with this method.
-(IBAction)textFieldReturn:(id)sender
{
    [sender resignFirstResponder];


}

// Use this method also if you want to hide keyboard when user touch in background

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [emailTextField resignFirstResponder];
    [passTextField resignFirstResponder];
}
[self.view endEditing:YES];
我遵循了本教程:它对我有效:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    UITouch *touch = [[event allTouches] anyObject];
    if ([_textField isFirstResponder] && [touch view] != _textField) {
        [_textField resignFirstResponder];
    }
    [super touchesBegan:touches withEvent:event];
}

这里的代码应该隐藏键盘。你能发一个你正在看的教程的链接吗?谢谢-这节省了我一点打字时间。=)