带有 UITextField 的键盘
我有一个列出一些字符串的表格,我想要的是当我点击导航栏上的添加按钮时,带有文本字段的键盘会跳起来,这样我就可以在文本字段中输入一个字符串,然后当我点击返回键时,键盘和文本字段都会消失,并且新字符串将添加到表中。
我已经用包含文本字段的工具栏创建了一个 nib 文件,但我无法继续。
我怎样才能实现这个想法?使用inputAccessoryView?如果是这样,这意味着属于工具栏的文本字段的 inputAccessoryView 将是工具栏本身!
这看起来有点奇怪,直到现在我还无法让它发挥作用。
或者这个想法还有其他方法吗?
多谢!
I have a table listing some strings, and what I want is when I tap the add button on the navigation bar, a keyboard with a textField would jump up, so I can input a string in the textField, then when I tap the return key, the keyboard disappear as well as the textField, and the new string is added to the table.
I already make up a nib file with a toolBar containing a textField, and I just failed to go on.
How can I implement this idea? Use the inputAccessoryView? If so, that means the inputAccessoryView of the textField which belongs to the toolBar is gonna be the toolBar itself!
This seem kind of weird and I have not been able to make it work till now.
Or is there another way for this idea?
Thanks a lot!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过使用通知而不是
inputAccessoryView
解决了问题。XCode 中有一个名为“KeyboardAccessory”的示例代码,它提供了有关使用键盘通知的一个很好的示例!
或者自定义一个带有选项卡的视图,并将其设置为textField的
inputAccessoryView
,这也可以!I've solved the problems by using notification instead of
inputAccessoryView
.There is a sample code in XCode called "KeyboardAccessory", and it gives a good example about using keyboard notifications!
Or custom a view with a tab, and set it as the textField's
inputAccessoryView
, that would also work!