[英]AddTarget does not work on UITextField rightView
I am adding following code to add a drop down button on UITextField right side 我正在添加以下代码以在UITextField右侧添加下拉按钮
self.filterTextView.rightViewMode = UITextFieldViewModeAlways;
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setFrame:CGRectMake(0, 0, 32, 32)];
[btn setBackgroundImage:[UIImage imageNamed:@"downArrow.png"] forState:UIControlStateNormal];
[btn addTarget:self action:@selector(showPicker:) forControlEvents:UIControlEventTouchUpInside];
self.filterTextView.rightView = btn;
Button is visible on right sie but showPicker
method doesn't get called when i tap on button 按钮在右侧sie上可见,但是当我点击按钮时showPicker
方法没有被调用
I am running the code in iOS 6 我正在iOS 6中运行代码
I'm running your code and it is working for me. 我正在运行您的代码,它正在为我工作。
Also, you can manage that without a button, you can use UITextFieldDelegate
. 此外,您可以管理没有按钮的情况,可以使用UITextFieldDelegate
。
self.filterTextView.delegate = self
- (void) textFieldDidBeginEditing:(UITextField *)textField
{
if (textField == self.filterTextView)
{
[self.filterTextView resignFirstResponder];
//here open picker
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.