IPad and UIPickerView (or UIDatePickerView)

Has anyone managed to use UIPicker in SDK 3.2? I'm in the middle of transferring an iPhone app to an iPad and that's one thing I can't seem to work with. I tried...

-Create an action sheet, add a collector as a subquery and display it.

-Create this above the action sheet making it look like a generic ViewController by adding that VC for the UIPopover

-Note only the generic ViewController view collector adding that VC for UIPopover

On the action sheet, he doesn't even try to draw it. In the popover view, it tries to draw, but it doesn't render correctly.

I just want to check if someone managed to do it, and if so, how.

Thanks everyone!

+2


a source to share


6 answers


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



Project example

+2


a source


I just wrestled with this for about 24 hours and got it to work by following this tutorial and wherever it mentions its UITableView just think about your UIPickerView and replace the relevant information.

Matthew Casey - Tutorial: Introduction to Pop Over Control on iPad



In short, on iPad, the ONLY way to show the picker is inside the popover control. Sharing data between the popover content view controller (selection view view controller) and the main application view controller is a bit I couldn't figure out. (ie getting the "didSelectRow" picker method to act on an object in your main view controller, such as a UITextField or UIButton.) This is handled by creating a custom protocol to pass the "didSelectRow" method to the main view controller.

I am in no way an expert on this, so I went step by step with this tutorial and it worked in the end. Before I found this tutorial, I was lost. (I am also porting the iPhone app to iPad.)

+3


a source


If you want to communicate between view controllers ... this is NSNotificationCenter.

I know this doesn't answer the whole question, but if I want to exchange data between view controllers: In the sending view controller

NSMutableDictionary *toshare = [[NSMutabledictionary alloc] init];
[toshare setValue:valueToShare forKey:@"shared"];
[[NSNotificationCenter defaultCenter] postNotificationName:@"imSharing" withObject:nil userInfo:(NSDictionary *)toshare];

      

In the controller of the receiving view: Place in the viewDidLoad

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(imSharing:) name:@"imSharing" object:nil];

      

then add this function:

-(void)imSharing:(NSNotification *)notification {
      NSDictionary *dictionary = [notification userInfo]; 
        //do something with [dictionary objectForKey:@"shared"];
        dictionary = nil;
}

      

This works for exchanging data between two view controllers ... well, small amounts of data anyway.

Otherwise, see here to learn more about Sharing Data Between View Managers

+2


a source


Are you using Interface Builder? It is much easier to create a new UIViewController subclass in Xcode with a nib file and then drag and drop it into the UIPicker. Then you need to expose the view controller to the popover. Action sheets are not meant to be viewed, so don't.

I did this: see third screen shot in C64 Paint .

+1


a source


Thanks for the answers everyone. So while I can't say what the initial problem was, I started this problem from scratch and made it work. I made brand new View Controllers and showed them in Popover and it worked well. This seems to be one of the toughest points in creating a universal app.

+1


a source


UIPickerView will work if you create it on iPad if you create it like this:

UIPickerView* pickerView = [[UIPickerView alloc]initWithFrame: CGRectMake (someX, someY, 320, 216)];

      

Several other sizes seem to work. But CGRectZero doesn't work on iPad - even if it works on iPhone.

0


a source







All Articles