Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Picker as inputview inside popover

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?

like image 661
Dash Avatar asked Jan 17 '12 00:01

Dash


1 Answers

You can not do this directly (as inputView). But you can certainly use this simple work around:

  1. 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..)

  2. 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.

  3. 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).

like image 188
Lukasz Avatar answered Nov 09 '22 19:11

Lukasz