Is it possible to set up a UITextField with a leftView so that if a user clicks into the UITextField the keyboard shows but if they click on an icon in the leftView another method is called (i.e., one that displays a UIPickerview)?
A:
Have you tried using a UIButton for this task? From the documentation for the leftView property:
If your overlay view does not overlap any other sibling views, it receives touch events like any other view. If you specify a control for your view, the control tracks and sends actions as usual. If an overlay view overlaps the clear button, however, the clear button always takes precedence in receiving events.
So create a UIButton instance, configure its appearance and actions as needed, then set it as the leftView property.
Danilo Campos
2010-01-04 04:39:38
Actually this does not work. Here's what I have: UIButton *detailButton = [[UIButton alloc] init]; [detailButton setImage:[UIImage imageNamed:@"textview-list-icon.png"] forState:UIControlStateNormal]; self.propertyField.leftView = detailButton; [detailButton release];The code compiles and runs without any errors or warnings in the console, but the button is not displayed. Have I misunderstood this?Thanks.
John Frankes
2010-01-04 22:52:58
Try setting the button's frame. Unless you specify a frame, it won't know where and how to draw itself, so you won't see it. That's why you generally want to use initWithFrame instead of init for UIView subclasses, so you won't have to be troubled with setting it later.
Danilo Campos
2010-01-05 08:51:42