当用户点击其他地方时,如何从文本字段中辞退第一响应者? [英] How to resign first responder from text field when user tap elsewhere?

查看:108
本文介绍了当用户点击其他地方时,如何从文本字段中辞退第一响应者?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用ScrollView填充了我的视图(与视图大小相同),当用户点击视图(或滚动视图)中的其他位置时,我仍然坚持如何辞退第一响应者。有关如何做到这一点的任何想法?我正在使用以下方法,但它没有按预期工作:

I have filled my view with ScrollView (same size as the view) and I'm stuck at how to resign first responder when user tap elsewhere in the View (or the scrollview). Any idea on how to do that ? I'm using the following method but it's not working as expected:

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}

Thx帮助,

Stephane

推荐答案

我在这里找到答案: link


如果你的最终目的只是让第一响应者辞职,这个
应该有效:[self.view endEditing:YES]

If your ultimate aim is just to resign the first responder, this should work: [self.view endEditing:YES]

这种方法适合它!
参考: endEditing:


导致视图(或其中一个嵌入的文本字段)辞职第一响应者状态。

Causes the view (or one of its embedded text fields) to resign the first responder status.

这篇关于当用户点击其他地方时,如何从文本字段中辞退第一响应者?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆