本文介绍了当按下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?

谢谢

推荐答案

请参阅:

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

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会执行操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 00:05