是否可以更改 MonoTouch 中的默认 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
该文档有点过时了。从 MonoTouch 3.2.0 开始就有了 setter。
The documentation is slightly out of date. There is a setter since MonoTouch 3.2.0.
凯文的答案会起作用对于 UIKeyboardType 键盘,但据我所知(我可能是错的),你不能以这种方式呈现自定义键盘。
我知道如何呈现自定义键盘的唯一方法是覆盖您希望呈现输入视图的 UIViewController 的 InputView 。
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.连接 UITextField 以处理适当的编辑事件,并在事件处理程序中选择 键盘类型你想要的。如果您不需要动态设置它,那么您可以在创建文本字段时设置该属性。
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.