0

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;


}
Prakash Desai
  • 511
  • 3
  • 14

1 Answers1

1

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;
Wain
  • 118,658
  • 15
  • 128
  • 151
  • could you modify the size of my popover pickerview and tool in code what size i should i set i dont have idea about that – Prakash Desai Aug 06 '13 at 07:20
  • Yes, you already set the frame of both, you just need to do it with sensible values so the origin of both views isn't the same. Try using the default size of both items and just setting the frame origins. – Wain Aug 06 '13 at 07:30
  • i do understand what you talking about sir but i dont know how to determine that cgrectmake size like you said that popover should be big enough that can hold both toolbar and timepicker and they both should be in that size like they fit popover perfectly so how to determine that perfect size of these all three things – Prakash Desai Aug 06 '13 at 07:34
  • sir i have done it but i have last question when we click any where then popover controller get disappear so i want same when done is clicked so could you tell me what is property of how can i disappear when user click on that done? – Prakash Desai Aug 06 '13 at 07:59
  • You need to connect a target and action to the button and dismiss the popover then the method is called. – Wain Aug 06 '13 at 08:01
  • yes i got it [popoverController dismissPopoverAnimated:YES]; thank you – Prakash Desai Aug 06 '13 at 09:09