是否可以更改 MonoTouch 中的默认 InputView?

发布于 2024-10-10 17:31:13 字数 506 浏览 9 评论 0原文

当文本字段成为第一响应者(即获得焦点)时,我想显示与标准键盘不同的视图(例如选择器控件或日期选择器)。这真的很好,因为目前我正在将包含选择器控件的自定义视图推送到导航堆栈上,用户在其中选择一个选项,然后单击“确定”或“取消”按钮。

根据 UITextField.InputView 的文档

为此分配自定义视图 属性导致该视图成为 而是呈现。

但是,它是只读的!

有解决方法吗?我是否需要实现自定义 UITextField 控件并以某种方式覆盖 InputView 属性?我需要调用某种本机函数吗?我真的很想必须做这两件事......但如果我必须这样做,那就这样吧。提前致谢!

I would like to display a different view than the standard keyboard (a picker control, or a date picker, for example) when a text field becomes first responder (i.e. gets focus). This would be really nice, because currently I'm pushing a custom view which contains my picker control onto the navigation stack where the user chooses an option, and then hits an OK or Cancel button.

According to the documentation for UITextField.InputView:

Assigning a custom view to this
property causes that view to be
presented instead.

But, It's read only!!!

Is there a workaround for this? Do I need to implement a custom UITextField control and somehow override the InputView property? Do I need to call some kind of native function? I'd really love not to have to do either of those things... but if I have to, so be it. Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梦魇绽荼蘼 2024-10-17 17:31:13

该文档有点过时了。从 MonoTouch 3.2.0 开始就有了 setter。

The documentation is slightly out of date. There is a setter since MonoTouch 3.2.0.

情域 2024-10-17 17:31:13

凯文的答案会起作用对于 UIKeyboardType 键盘,但据我所知(我可能是错的),你不能以这种方式呈现自定义键盘。

我知道如何呈现自定义键盘的唯一方法是覆盖您希望呈现输入视图的 UIViewController 的 InputView 。

UIView keyboardView;

public override UIView InputAccessoryView {
   get 
   {
       // create the view as you'd like here
       return keyboardView;
   }
}

Kevin's answer will work for UIKeyboardType keyboards but as far as I'm aware (I could be wrong) you can't present a custom keyboard this way.

The only way I know how to present a custom keyboard is to override the InputView for the UIViewController you wish to present the input view.

UIView keyboardView;

public override UIView InputAccessoryView {
   get 
   {
       // create the view as you'd like here
       return keyboardView;
   }
}
所谓喜欢 2024-10-17 17:31:13

连接 UITextField 以处理适当的编辑事件,并在事件处理程序中选择 键盘类型你想要的。如果您不需要动态设置它,那么您可以在创建文本字段时设置该属性。

UITextField tf;
...
tf.KeyboardType = UIKeyboardType.PhonePad; // whatever kb you want

Wire up the UITextField to handle the appropriate editing event and in the event handler select the KeyboardType you want. If you don't need to dynamically set it then you can just set the property when you create the text field.

UITextField tf;
...
tf.KeyboardType = UIKeyboardType.PhonePad; // whatever kb you want
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文