Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/334.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/118.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
如何隐藏数字键盘,I';m使用Xamarin iOS(C#)_C#_Ios_Xamarin_Xamarin.ios - Fatal编程技术网

如何隐藏数字键盘,I';m使用Xamarin iOS(C#)

如何隐藏数字键盘,I';m使用Xamarin iOS(C#),c#,ios,xamarin,xamarin.ios,C#,Ios,Xamarin,Xamarin.ios,我找到了关于objective-C的问题的答案,但我不想在Xamarin iOS中搜索它。 所以我有一个用户写电话号码的字段,当这个字段编辑出现在键盘上,数字键盘类型。但是这个键盘不隐藏,也没有隐藏按钮 在针对此问题的android应用程序中,我使用以下代码: one.Click += delegate { InputMethodManager imm = (InputMethodManager)GetSystemService(Context.Input

我找到了关于objective-C的问题的答案,但我不想在Xamarin iOS中搜索它。 所以我有一个用户写电话号码的字段,当这个字段编辑出现在键盘上,数字键盘类型。但是这个键盘不隐藏,也没有隐藏按钮

在针对此问题的android应用程序中,我使用以下代码:

one.Click += delegate
        {
            InputMethodManager imm = (InputMethodManager)GetSystemService(Context.InputMethodService);
            imm.HideSoftInputFromWindow(ulitsa.WindowToken, 0);
        };
在我的iOS应用程序中,此代码不起作用。 我在iOS中的代码:

            tel.ShouldReturn = delegate {
            tel.ResignFirstResponder ();

            //tel.ReturnKeyType = UIReturnKeyType.Done;

            return true;
        };
此代码适用于默认键盘类型。在键盘类型数字键盘中,我得到了屏幕截图:

如何解决我的问题?

你可以看到这一点。这可能对你有很大帮助

public override void ViewDidLoad ()
{
base.ViewDidLoad ();

// Your stuff

NSNotificationCenter.DefaultCenter.AddObserver   ("UIKeyboardWillShowNotification", KeyboardWillShow);
}

 public void KeyboardWillShow(NSNotification notification)
 {
 var doneButton = new UIButton (UIButtonType.Custom);
 doneButton.Frame = new RectangleF (0, 163, 106, 53);
 doneButton.SetTitle ("DONE", UIControlState.Normal);
 doneButton.SetTitleColor (UIColor.Black, UIControlState.Normal);
 doneButton.SetTitleColor (UIColor.White, UIControlState.Highlighted);

 doneButton.TouchUpInside += (sender, e) => 
 {
 // Make the Done button do its thing!  The textfield shouldn't be the   first responder
 _txtNumbers.ResignFirstResponder();
 };

 // This is the 'magic' that could change with future version of iOS
 var keyboard = _txtNumbers.WeakInputDelegate as UIView;
 if (keyboard != null)
 {
     keyboard.AddSubview (doneButton);
 }
}
或者您也可以使用此代码

 this.View.EndEditing(true);
你可以看到这个。这可能对你有很大帮助

public override void ViewDidLoad ()
{
base.ViewDidLoad ();

// Your stuff

NSNotificationCenter.DefaultCenter.AddObserver   ("UIKeyboardWillShowNotification", KeyboardWillShow);
}

 public void KeyboardWillShow(NSNotification notification)
 {
 var doneButton = new UIButton (UIButtonType.Custom);
 doneButton.Frame = new RectangleF (0, 163, 106, 53);
 doneButton.SetTitle ("DONE", UIControlState.Normal);
 doneButton.SetTitleColor (UIColor.Black, UIControlState.Normal);
 doneButton.SetTitleColor (UIColor.White, UIControlState.Highlighted);

 doneButton.TouchUpInside += (sender, e) => 
 {
 // Make the Done button do its thing!  The textfield shouldn't be the   first responder
 _txtNumbers.ResignFirstResponder();
 };

 // This is the 'magic' that could change with future version of iOS
 var keyboard = _txtNumbers.WeakInputDelegate as UIView;
 if (keyboard != null)
 {
     keyboard.AddSubview (doneButton);
 }
}
或者您也可以使用此代码

 this.View.EndEditing(true);

另一种方法是使用工具栏


另一种方法,使用工具栏


您可以创建一个基类,其中包含可在其他ViewController中使用的helpers方法

i、 e:

当然,您必须在故事板中定义数字文本字段的名称

该键的功能类似于adddonebuttonomnumerickeyboard()

最终结果如下所示:

您可以创建一个基类,其中包含可在其他ViewController中使用的helpers方法

i、 e:

当然,您必须在故事板中定义数字文本字段的名称

该键的功能类似于adddonebuttonomnumerickeyboard()

最终结果如下所示:

这不是标准的方法。导航面板上的Common decision-Done按钮,或者您可以在键盘上添加自定义按钮。如何在键盘上添加按钮?也许你有例子?在objective-c上,这不是标准的方法。导航面板上的Common decision-Done按钮,或者您可以在键盘上添加自定义按钮。如何在键盘上添加按钮?也许你有一个例子?在objective-c上,什么类型有这个变量“\u txtNumbers”?var\u txtNumbers=new UITextField(new RectangleF(5,50,200,20));_txtNumbers.KeyboardType=UIKeyboardType.NumberPad;_txtNumbers.BorderStyle=UITextBorderStyle.RoundedRect;View.AddSubview(_txtNumbers);你可以在这里找到整个项目。在此字符串中,“NSNotificationCenter.DefaultCenter.AddObserver(“UIKeyboardWillShowNotification”,KeyboardWillShow);“我有2个异常1)”错误CS1502:
Foundation.NSNotificationCenter.AddObserver(Foundation.NSString,System.Action)的最佳重载方法匹配具有一些无效参数(CS1502)“2)“错误CS1503:参数
#1'无法将
string”表达式转换为类型
Foundation.NSString'(CS1503)“您从github下载应用程序并进行测试了吗?什么类型有此变量“_txtNumbers”?var _txtNumbers=new UITextField(new RectangleF(5,50,200,20))txtNumbers.KeyboardType=UIKeyboardType.NumberPad;txtNumbers.BorderStyle=UIExtBorderStyle.RoundedRect;View.AddSubview(txtNumbers);您可以在这里找到整个项目;“我有2个异常1)”错误CS1502:与
Foundation.NSNotificationCenter.AddObserver(Foundation.NSString,System.Action)”匹配的最佳重载方法具有一些无效参数(CS1502)”2)“错误CS1503:参数
#1”无法将
string”表达式转换为类型
Foundation.NSString'(CS1503)“您是否从github下载了该应用程序并进行了测试?即使您有多个数字字段,该解决方案也能像charm一样工作。谢谢你,这个解决方案很有魅力,即使你有多个数字字段。谢谢你,伙计