如何在iitableviewcell中将textfield作为第一响应者

7 iphone cocoa-touch objective-c uitableview uitextfield

我用这个代码辞职我UITextFieldfirstResponder使用标准时UIView.

但是我现在已经UITextField在我的UITableViewCellin中了UITableView,当我在textField外面单击时,代码不会将textfield作为第一响应者辞职.任何想法如何使这项工作?

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

    UITouch *touch = [[event allTouches] anyObject];
    if ([self.temperatureTextField isFirstResponder] && [touch view] != self.temperatureTextField) {
        [self.temperatureTextField resignFirstResponder];
    }
    [super touchesBegan:touches withEvent:event];
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

Mat*_*ing 15

[[self tableView] endEditing:YES]; 是我的标准方法.