I'm using a popover to show a table view form that is iPhone sized (matches my iPhone app). Inside the table I have a textfield that has a picker set as an input view. When it's used this way as an iPad the picker slide up like the iPad keyboard. Is there anyway to set the picker to slide up within the popover just like it would on the iPhone?
You can not do this directly (as inputView). But you can certainly use this simple work around:
Replace your UITextField
with UIButton and connect it to some selector (buttonClicked:). You can use UIButtonTypeCustom
to be able to style it so it looks like text field (set layer's bordeColor, borderWidth, cornerRadius
, etc..)
in -(void)buttonClicked:(id)sender
- toggle the same UIPickerView you would use as inputView for replaced UITextField
. You can make in ordinary instance variable, just remember to set delegate and dataSource. Attach it to the root view (of your UIViewController
show in popover) or even UIWindow
and animate it in or out (toggle) depending if it is already shown or not.
update button's text (by using [button setTitle:<selected_value> forState:UIControlStateNormal]
) in UIPickerViewDelegate
method: pickerView:didSelect...atIndex:` - you can additionally hide picker here..
I have done it multiple times, it always works in any circumstances and you have complete control over how and where picker is shown without involving UIResponder
chain.
Didn't find better solution for such a special cases yet (iPad keyboard likes to manipulate popovers also - it pushes them up).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With