开发者

UIPopoverView problem adding toolbar

开发者 https://www.devze.com 2023-03-15 09:14 出处:网络
I have the code below which works fine in terms of the date picker being shown correctly but the toolbar and segmented control is never displayed. All I really want is a button at the bottom of my pop

I have the code below which works fine in terms of the date picker being shown correctly but the toolbar and segmented control is never displayed. All I really want is a button at the bottom of my popover 'OK' to be clicked when the user has selected their chosen date.

if ([self amIAnIPad]) {
    [tf resignFirstResponder];
    self.datePopOverContent = [[UIViewController alloc] init];

    UIView *popOverView = [[UIView alloc] initWithFrame:CGRectMake(0,0,300,180)];

    popOverView.backgroundColor = [UIColor blueColor];
    self.datePickerView.frame = CGRectMake(0,0,300,180);



    //[self.menuActionSheet addSubview:self.datePickerView];
    [popOverView addSubview:self.datePickerView];
    self.datePopOverContent.view = popOverView;

    self.datePopOverContent.contentSizeForViewInPopover = CGSizeMake(300.0,180.0);

    se开发者_如何学编程lf.datePopOverController = [[UIPopoverController alloc] initWithContentViewController:self.datePopOverContent];

    [self.datePopOverController presentPopoverFromRect:self.datePickerTextField.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
    self.datePopOverController.delegate = self;

    NSArray *segmentedItems = [NSArray arrayWithObjects:@"Bookmarks", @"Recents", @"Contacts", nil];
    UISegmentedControl *ctrl = [[UISegmentedControl alloc] initWithItems:segmentedItems];
    ctrl.segmentedControlStyle = UISegmentedControlStyleBar;
    ctrl.selectedSegmentIndex = 0;

    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:ctrl];
    ctrl.frame = CGRectMake(0.0f, 5.0f, 300.0f, 30.0f);

    NSArray *theToolbarItems = [NSArray arrayWithObjects:item, nil];
    [self.datePopOverContent setToolbarItems:theToolbarItems];
    [ctrl release];
    [item release];

    [popOverView release];
    [self.datePopOverContent release];
}

Any help would be appreciated.

Many thanks

Chris

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号