I am adding following code to add a drop down button on UITextField right side
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
I am running the code in 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
.
self.filterTextView.delegate = self
- (void) textFieldDidBeginEditing:(UITextField *)textField
{
if (textField == self.filterTextView)
{
[self.filterTextView resignFirstResponder];
//here open picker
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.