Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 单触式iphone-单击“清除”时隐藏键盘(x)_.net_Iphone_Xamarin.ios - Fatal编程技术网

.net 单触式iphone-单击“清除”时隐藏键盘(x)

.net 单触式iphone-单击“清除”时隐藏键盘(x),.net,iphone,xamarin.ios,.net,Iphone,Xamarin.ios,我的问题与在iphone开发中使用monotouch有关 我的布局很简单,它是一个工具栏,里面有一个文本框。 我已启用文本框上的“清除”按钮选项 我将一些代码放在一起,如下所示:每次按键都会调用我的代理,因此,如果用户清除文本框中的所有字符,iphone键盘就会消失 但是,如果用户选择文本框上的clear(x)按钮,代理仍会被触发(我已选中此项),但辞职的FirstResponder不会隐藏键盘 txtReply.EditingChanged += delegate {

我的问题与在iphone开发中使用monotouch有关

我的布局很简单,它是一个工具栏,里面有一个文本框。 我已启用文本框上的“清除”按钮选项

我将一些代码放在一起,如下所示:每次按键都会调用我的代理,因此,如果用户清除文本框中的所有字符,iphone键盘就会消失

但是,如果用户选择文本框上的clear(x)按钮,代理仍会被触发(我已选中此项),但辞职的FirstResponder不会隐藏键盘

txtReply.EditingChanged  += delegate {
                    if ( txtReply.Text == "" ) {
                        txtReply.ResignFirstResponder();
                    }
        };
有什么想法吗?

试试这个:

替换: (txtReply.Text==“”)

为此:
(txtReply.Text==nil | |[txtReply.Text length]==0)

您需要对UITextFieldDelegate进行子类化,并重写ShouldClear方法。当按下内置的清除按钮时,UITextField调用此方法。子类化看起来像。在overrode方法中,该方法传递文本字段,您可以检查文本是否为空,如果为空,请关闭键盘。

hi-这不起作用。这段代码实际上是在点击txtReply.ResignFirstResponder()行——它只是没有隐藏键盘。txtReply.Text=”“当我点击clear(x)时。嗨@Kevin McMahon,奇怪的是,我认为这应该是可行的。该方法被命中,但不起作用。这是我的代码:我想我应该提到我的文本框包含在boldUIToolbar中。
txtReply.EditingChanged  += delegate {
                    if ( txtReply.Text == "" ) {
                        txtReply.ResignFirstResponder();
                    }
        };