Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在视图上有一个常规文本字段,我想使用 iPhone 键盘上的搜索按钮。对于我的生活,我无法弄清楚如何做到这一点。似乎没有任何事件暴露,我可以连接与键盘上的搜索按钮特别相关的事件。我已经用谷歌搜索了,但我也没有找到与这个主题相关的任何东西。
通过设置返回键类型,使键盘显示蓝色的“搜索”按钮。
myTextField.returnKeyType = UIReturnKeySearch;
将您的文本字段的委托设置为您的控制器并实现“textFieldShouldReturn:”方法。
- (BOOL)textFieldShouldReturn:(UITextField *)textField { [textField resignFirstResponder]; /* Do some searching here */ return YES; }