15

I'm not trying to resize the PickerView's height. I'm fine with having the default size, which I believe is 320 x 216. I created this code to present a pickerView in my popovercontroller, however, I get these messages on the console:

2

011-06-30 13:18:28.125 MiGenome[64357:207] -[UIPickerView setFrame:]: invalid height value 1024.0 pinned to 216.0 
2011-06-30 13:18:28.126 MiGenome[64357:207] -[UIPickerView setFrame:]: invalid height value 448.0 pinned to 216.0 
2011-06-30 13:18:28.127 MiGenome[64357:207] -[UIPickerView setFrame:]: invalid height value -16.0 pinned to 162.0 

I don't know why I get this since I'm trying to use the picker default size in the popover. Here's my code. Thanks.

- (IBAction)presentSortPopover {
    UIViewController *sortViewController = [[UIViewController alloc] init];

    UIPickerView *sortPickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 0, sortViewController.view.bounds.size.width, sortViewController.view.bounds.size.height)];
    sortViewController.view = sortPickerView;
    sortViewController.contentSizeForViewInPopover = CGSizeMake(320, 216);
    sortPickerView.delegate = self;
    sortPickerView.dataSource = self;
    sortPickerView.showsSelectionIndicator = YES;

    self.SortPopover = [[UIPopoverController alloc] initWithContentViewController:sortViewController];
    [self.SortPopover presentPopoverFromRect:_sortButtonPop.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

    [sortPickerView release];
    [sortViewController release];
}
Crystal
  • 28,460
  • 62
  • 219
  • 393
  • What are the bounds (size/width) of your sortViewController? You're setting the frame of the UIPickerView to that in your initWithFrame method; if it's not the size you want, you'll have to change the CGRectMake call to include the correct value. – Zeppomedio Jun 30 '11 at 20:33
  • Yeah I tried that originally also. I tried creating the frame of my sortViewController to be 320,216 as well, but I still get those statements on the console. Also, if I changed the height of the 216 to 500, I would NOT see any change. I only saw change if I changed the contentSizeForViewInPopover property. – Crystal Jun 30 '11 at 21:36
  • 1
    Any luck with this issue. I am having that exact same problem. I think the Popover is trying to resize the frame of the picker. – Bach Jul 20 '11 at 06:33

3 Answers3

10

I had the same problem until I embedded the UIPickerView in a generic UIView with the same dimensions (0, 0, 320, 216), and set the view controller's view property to the UIView.

Also, I used the setPopoverContentSize:animated: method on the UIPopoverViewController to set the popover dimensions, rather than setting it on the UIViewController.

Hope that helps.

Simon Lawrence
  • 564
  • 2
  • 8
  • 1
    I was also getting the `-[UIPickerView setFrame:]: invalid height value`... error because I had set the autoresizingMask on the UIPickerView. – Heath Borders Jun 19 '12 at 21:41
1

I think this line is the culprit.

UIPickerView *sortPickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 0, sortViewController.view.bounds.size.width, sortViewController.view.bounds.size.height)];

try

UIPickerView *sortPickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 0, 320, 216)];
NWCoder
  • 5,296
  • 1
  • 26
  • 23
  • Yeah that's what I originally had. I tried originally making the rect 320, 216, then I thought maybe that was giving me the problem. So I tried not setting it to a number, and just fill out the frame. Unfortunately, I get the error both ways. :-\. Thanks for your input though! – Crystal Jun 30 '11 at 20:58
1

UIViewController has a method called contentSizeForViewInPopover. If you set the expected size for your view controller using it (using a CGSize) you will be able to prevent the UIPopoverController from resizing itself wrong.

yuvalz
  • 165
  • 2
  • 7