UIPopover not displaying correctly from UIButton?

If it is not a direct subview of your view then your coordinate space is off. Try changing your code to.

Up vote 2 down vote favorite 1 share g+ share fb share tw.

I have a UIButton that when clicked, displays a UIPopover with a UIDatePicker in it. It is supposed to display under button for date of birth, but it is covering it instead. This is the code I have: - (IBAction)dateOfBirthButtonPressed:(id)sender{ UIViewController* popoverContent = UIViewController alloc init; UIView *popoverView = UIView alloc init; popoverView.

BackgroundColor = UIColor blackColor; UIDatePicker *datePickerTemp = UIDatePicker allocinit; datePickerTemp. Frame=CGRectMake(0,44,320, 216); datePickerTemp. DatePickerMode = UIDatePickerModeDate; datePickerTemp.

MaximumDate = NSDate date; self. DatePicker = datePickerTemp; popoverView addSubview:self. DatePicker; UIToolbar *toolbar = UIToolbar alloc init; toolbar.

Frame=CGRectMake(0,0 ,320, 40); toolbar. BarStyle = UIBarStyleBlackOpaque; NSMutableArray *toolbarItems = NSMutableArray array; UIBarButtonItem *cancelButton1 = UIBarButtonItem allocinitWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(datePickerCancelButtonClicked); UIBarButtonItem *doneButton1 = UIBarButtonItem allocinitWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(datePickerSaveButtonClicked); UIBarButtonItem *space = UIBarButtonItem alloc initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil; toolbarItems addObject:cancelButton1; toolbarItems addObject:space; toolbarItems addObject:doneButton1; toolbar. Items = toolbarItems; popoverView addSubview:toolbar; cancelButton1 release; space release; toolbar release; popoverContent.

View = popoverView; UIPopoverController *popoverController = UIPopoverController alloc initWithContentViewController:popoverContent; popoverController. Delegate=self; self. DatePopoverController = popoverController; popoverContent release; popoverView release; self.

DatePopoverController setPopoverContentSize:CGSizeMake(320, 264) animated:NO; self. DatePopoverController presentPopoverFromRect:self. DateOfBirthButton.

Frame inView:self. View permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES; } NSLog for frame: DOB button: {{160, 129}, {329, 37}} Last name label: {{160, 77}, {329, 31}} iphone objective-c cocoa-touch uipopovercontroller uidatepicker link|improve this question edited Dec 17 '11 at 22:31 asked Dec 17 '11 at 21:54Jon881212 97% accept rate.

Your code looks correct. Could you perhaps NSLog the frame locations/sizes of the DOB button and the last name fields before calling presentPopoverFromRect? – dasblinkenlight Dec 17 '11 at 22:01 Ok, thanks.

I added the NSLog output in the question. – Jon Dec 17 '11 at 22:16 The logged numbers look suspicious: they say that the DOB button and the last name label are vertically aligned at 160, but the button (covered by the popover in the picture) is well to the right of the last name label. – dasblinkenlight Dec 17 '11 at 22:27 Sorry the pic I used was a little old, let me upload the correct picture that goes with the code I posted.

– Jon Dec 17 '11 at 22:29 Ok, I added the new picture, sorry about that. – Jon Dec 17 '11 at 22:31.

If it is not a direct subview of your view then your coordinate space is off. Try changing your code to: CGRect buttonRect = self. DateOfBirthButton convertRect:self.

DateOfBirthButton. Frame toView:self. View; self.

DatePopoverController presentPopoverFromRect:buttonRect inView:self. View permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES.

You can try either one of these to see that fix the problem. The second one fix my problem that is similar to yours. Self.

DatePopoverController presentPopoverFromRect:self. DateOfBirthButton. Frame inView:self.

DateOfBirthButton permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES; or self. DatePopoverController presentPopoverFromRect:self. DateOfBirthButton.

Frame inView:self. DateOfBirthButton. Superview permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions