Reputation: 511
i want to put tool bar and picker view as sub view of popovercontroller and for that i do following and so far my picker view is displaying perfectly but just above that i also want to display my tool bar in which there is button named Done for that i do following please guide me if you see something wrong that i am doing
- (IBAction)setAlarm:(id)sender {
UIViewController* popoverContent = [[UIViewController alloc] init];
UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 344)];
popoverView.backgroundColor = [UIColor whiteColor];
[popoverView addSubview:toolbar];
[popoverView addSubview:timePicker];
timePicker.hidden = NO;
toolbar.hidden = NO;
popoverContent.view = popoverView;
//resize the popover view shown
//in the current view to the view's size
popoverContent.contentSizeForViewInPopover = CGSizeMake(320, 216);
//create a popover controller
popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
timePicker.frame = popoverView.bounds;
toolbar.frame = popoverView.bounds;
CGRect popoverRect ;
popoverRect.origin.x =591;
popoverRect.origin.y = 139;
popoverRect.size.height = 95;
popoverRect.size.width = 44;
[popoverController presentPopoverFromRect:popoverRect
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionUp
animated:YES];
//release the popover content
[popoverView release];
[popoverContent release];
timePicker.hidden = NO;
toolbar.hidden = NO;
}
Upvotes: 0
Views: 312
Reputation: 119031
The problem is that you set the frame of booth subviews to the same value:
timePicker.frame = popoverView.bounds;
toolbar.frame = popoverView.bounds;
So, which ever one was added first will be hidden behind the other. You need to set the frames so that the toolbar is correctly positioned above the picker (and size the popover to allow space for both of them).
Something like:
CGRect toolbarFrame = toolbar.frame;
toolbarFrame.size.width = 320;
toolbar.frame = toolbarFrame;
CGRect pickerFrame = timePicker.frame;
pickerFrame.origin.y = toolbarFrame.size.height;
pickerFrame.size.width = 320;
timePicker.frame = pickerFrame;
popoverView.frame = CGRectMake(0, 0, 320, pickerFrame.origin.y + pickerFrame.size.height);
popoverContent.contentSizeForViewInPopover = popoverView.frame.size;
Upvotes: 1