views:

1686

answers:

4

Hey all,

Has anyone had any luck using a UIPicker in the 3.2 SDK? I'm in the middle of porting an iPhone application over to an iPad and that's the one thing I can't seem to get to work. I've tried...

-Creating an action sheet, add the picker as a subview and displaying it.

-Creating that above action sheet, making it the view of a generic ViewController, adding that VC to a UIPopover

-Making just the picker the view of a generic ViewController, adding that VC to a UIPopover

With the action sheet it doesn't even attempt to draw it. In the popover view it attempts to draw but doesn't get rendered correctly.

Just wanted to check to see if anyone has accomplished this and if so how.

Thanks everyone!

A: 

Are you using Interface Builder? It's a lot easier to create a new UIViewController subclass in Xcode with the nib file, and then drag in the UIPicker. Then you need to present the view controller in a popover. Action sheets are not designed to have subviews, so don't do that.

I have done it: see the third screenshot in C64 Paint.

lucius
A: 

I just struggled with this for about 24 hours and got it to work by following this tutorial and wherever he mentions his UITableView, just think about your UIPickerView and replace the appropriate info.

Matthew Casey - Tutorial: Introduction to Pop Over Control on iPad. http://tiny.cc/sgqjx

In short, on the iPad, the ONLY way you can show a picker is inside a popover control. Sharing data between the popover's content view controller (the picker view's view controller) and the main app's view controller is the bit I couldn't figure out. (i.e. getting the picker's "didSelectRow" method to affect an object in your main view controller, say a UITextField or UIButton.) This is handled by creating a custom protocol to forward the "didSelectRow" method to the main view controller.

I'm by no means an expert at this stuff, so I went step by step with that tutorial and it DID work in the end. Before I found that tutorial I was lost. (I am also porting over an iPhone app to iPad.)

Chris B
A: 

Thanks for the responses everyone. So while I can't say what the initial problem was, I started the problem from scratch and got it to work. I made completely new View Controllers and displayed them in a Popover and it worked well. Seems to be one of the tougher points of making a universal app.

Staros
+1  A: 

Hi there,

I am the author of the tutorial mentioned above. For a picker to work in a popover and add the selected value to the textbox in the main view you need to use protocols. I have created a sample project to show this. I will be creating a tutorial on this soon.

Sample Project

Matthew Casey