iPhone 文本输入,带有完成和“完成”按钮(不是搜索)
使用 iPhone SDK 3.0,我希望允许在键入时显示带有(可选)完成选项的文本输入,即也允许自由格式输入。因此,我使用 UISearchBar (具有文本更改事件)和 UISearchDisplayController 来呈现选项。
问题是我希望“完成”按钮显示“完成”而不是“搜索”,但是我找不到设置它的方法。显然我觉得我错过了一些东西,或者 SDK API 的 Interface Builder 需要设置一些属性。
我已经看到其他应用程序(在商店中)已经实现了我想要的结果(自由格式输入、完成、完成按钮),所以也许我缺少另一种方法。预先感谢您的任何指点。
Using iPhone SDK 3.0, I wish to allow text entry with (optional) completion options that appear as typing is occurring, i.e. also allowing freeformat entry. As such I am using a UISearchBar (which has the text change events) and a UISearchDisplayController to present options.
The problems is I want the DONE button to say DONE and not SEARCH, however I cannot find a way to set that. Clearly I feel I am missing something, or Interface Builder of the SDK API would have some property to set.
I have seen other apps (in the store) that have achieved the result I want (free format entry, completion, DONE button) so maybe there is an alternative approach I am missing. Thanks in advance for any pointers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
+1对于wal的答案,但为了安全起见,并对进一步版本中视图层次结构中可能的变化做出正确反应,请考虑使用以下代码:
+1 For wal's answer, but to be on the safe side, and properly react to possible changes in the view hierarchy in further releases consider using this code:
只是必须准确地实现这一点,并且在任何地方都找不到任何好的答案......所以我想我会提供一些见解。单步执行调试器并深入研究 UISearchBar ,这是非常明显的。我刚刚在 uisearchbar 子视图中找到了 UITextView,此时,一旦掌握了 UITextView 的句柄,您就应该能够在该 UITextView 上设置 returnkeytype。
伪代码-
UISearchBarObject.SubViewAtIndexOfUITextField.ReturnKeyType = UIReturnKeyType.Done
Just had to implement exactly this and couldn't find any great answers anywhere... so I thought I'd provide some insight. Stepping through the debugger and digging into UISearchBar it is pretty obvious. I just ended up finding the UITextView within the uisearchbar subviews and at that point then you should be able to set the returnkeytype on that UITextView once you get a handle on it.
Psuedocode-
UISearchBarObject.SubViewAtIndexOfUITextField.ReturnKeyType = UIReturnKeyType.Done
将此代码放入 viewDidLoad 中。
Put this code in viewDidLoad.
奇怪的是,UISearchBar 应该像 UITextField 和 UITextView 一样支持 UITextInputTraits 接口(文档中没有说明),因此应该具有 returnKeyType。无论如何我都会尝试一下。
如果没有,也许 UISearchBar 使用的对象之一具有此选项。
Odd, UISearchBar should support the UITextInputTraits interface like UITextField and UITextView do (it doesn't say it does in the documentation) and thus should have returnKeyType. I'd try it anyway.
If it doesn't, maybe one of the objects that UISearchBar uses has this option.