0

I am making application in Ipad i have taken one pickerviewController in Xib and i show it when user click on particular button now i am trying to put that picker view in popover this is how i am trying to achieve this tast

pickerView.hidden=FALSE;
i have created outlet of picker and i unhide it here 

    UIViewController* popoverContent = [[UIViewController alloc] init];
    UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 344)];
    popoverView.backgroundColor = [UIColor whiteColor];


    [popoverView addSubview:pickerView];
    popoverContent.view = popoverView;


    popoverContent.contentSizeForViewInPopover = CGSizeMake(320, 244);

    //create a popover controller
  UIPopoverController  *popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
    CGRect popoverRect;
    popoverRect.origin.x =323;
    popoverRect.origin.y = 713;
    popoverRect.size.height = 215;
    popoverRect.size.width = 70;




    [popoverController presentPopoverFromRect:popoverRect
     inView:self.view
     permittedArrowDirections:UIPopoverArrowDirectionDown
     animated:YES];


    //release the popover content
    [popoverView release];
    [popoverContent release];

now the Issue Is that my popover is displaying but it is totally black I am struggling on this please tell me what am i doing wrong or correct the code thank you for help

java
  • 239
  • 5
  • 20
  • Try to set the frame of the picker view to be equal to popover bounds. You should also remove the pickerview from its previous superview. – Valent Richie Jun 12 '13 at 12:58
  • i understand how to set picker view same as popover but how to remove that from super view can you show something – java Jun 12 '13 at 12:59
  • i dont know how to set size too :( – java Jun 12 '13 at 13:02
  • Try `[pickerView removeFromSuperview];` and you will need to make pickerView strong property so that it will not be released after it is removed from superview. – Valent Richie Jun 12 '13 at 13:04
  • Try `pickerView.frame = popoverView.bounds;` for setting the frame. – Valent Richie Jun 12 '13 at 13:05
  • ok i set it by contentSizeForViewInPopover but nothing happened – java Jun 12 '13 at 13:06
  • popoverContent.contentSizeForViewInPopover = CGSizeMake(320, 216); which is size of my picker – java Jun 12 '13 at 13:07
  • yes yes yes that happen but when i selection is done then only pickerview disappear pop over should disappear too – java Jun 12 '13 at 13:10
  • you should keep a reference to the pop over view controller and call dismissPopoverAnimated to dismiss it – Valent Richie Jun 12 '13 at 13:29
  • thank you so much you really helped me why dont you put this as your answer so i can accept it and up vote it – java Jun 13 '13 at 14:03

1 Answers1

1

Seems your picker view is hidden somewhere in the pop over because the frame is not properly set yet. So try to set the frame of the picker view to be equal to the bounds of the pop over as a starting point:

pickerView.frame = popoverView.bounds;

But before adding the picker view as a subview in the pop over, you need to remove the picker view properly from the superview.

Now, by default Xcode will generate the IBOutlet as weak property, and this will cause the picker view to be deallocated when it is removed from the superview. So you will need to declare the picker view as a strong property first.

After that, you can remove it from the current superview:

[pickerView removeFromSuperview];

You should keep a reference to the pop over view controller, for example declaring it is a property, and call dismissPopoverAnimated to dismiss the pop over properly.

Valent Richie
  • 5,226
  • 1
  • 20
  • 21