当按下UITextField / UISearchBar的清除按钮时,iPhone会执行操作 [英] iPhone perform action when UITextField / UISearchBar's clear button is pressed

查看:149
本文介绍了当按下UITextField / UISearchBar的清除按钮时,iPhone会执行操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以访问委托方法,以便在UITextField / UISearchBar上按下清除按钮时执行其他操作?

Is it possible to gain access to a delegate method that will allow additional actions to be performed when the "clear" button is pressed on a UITextField / UISearchBar?

谢谢

推荐答案

请参阅: UITextFieldDelegate Protocol Reference

如果将视图控制器设置为文本字段的委托(可以在界面构建器中完成),则可以使用:

If you set your view controller as the delegate for your text field (can be done in interface builder), you can use:

- (void)clearSearchTextField
{
  ...
}

- (BOOL)textFieldShouldClear:(UITextField *)textField
{
  if (textField == self.searchTextField) [self clearSearchTextField];
  return YES;
}

这篇关于当按下UITextField / UISearchBar的清除按钮时,iPhone会执行操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆