Search code examples
ipaduiactionsheetuipicker

UIPicker / UIActionSheet works fine on iPhone but only thin line on iPad


The following Code works fine on iPhone, but not on iPad. Only get a thin line instead of the full view. Have been researching and maybe something with the rect for the picker? All size numbers seem to be reasonable.

    actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:nil
    cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
    [actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
    CGRect pickerFrame = CGRectMake(0, 40, 0, 0);
    if ( isipad ) pickerFrame = CGRectMake(0, 345, 400, 216);
    pickerView = [[UIPickerView alloc] initWithFrame:pickerFrame];
    pickerView.showsSelectionIndicator = YES;
    pickerView.dataSource = self;
    pickerView.delegate = self;
    [actionSheet addSubview:pickerView];
    [pickerView release];
    UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray         arrayWithObject:@"Select"]];
    closeButton.momentary = YES; 
    closeButton.frame = CGRectMake(10, 7.0f, 100.0f, 30.0f);
    closeButton.segmentedControlStyle = UISegmentedControlStyleBar;
    closeButton.tintColor = [UIColor blackColor];
    [closeButton addTarget:self action:@selector(dismissActionSheet:)  forControlEvents:UIControlEventValueChanged];
    [actionSheet addSubview:closeButton];
    [closeButton release];
    UISegmentedControl *skipButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"Skip Birth Year"]];
    skipButton.momentary = YES; 
    skipButton.frame = CGRectMake(200, 7.0f, 100.0f, 30.0f);
    skipButton.segmentedControlStyle = UISegmentedControlStyleBar;
    skipButton.tintColor = [UIColor blackColor];
    [skipButton addTarget:self action:@selector(skipActionSheet:)   forControlEvents:UIControlEventValueChanged];
    [actionSheet addSubview:skipButton];
    [skipButton release];
    [actionSheet setBounds:CGRectMake(0, 0, self.view.frame.size.width, 216)];
    [actionSheet showInView:self.view];
    [actionSheet setBounds:CGRectMake(0, 0, self.view.frame.size.width, 216)];

Solution

  • Well, got it to work by putting most of the code in

        - (void)willPresentActionSheet:(UIActionSheet *)actionSheet
    

    including

        pickerFrame = CGRectMake(0, 0, 320, 214);
    

    AND

        initWithTitle:@"\n\n\n\n\n\n\n\n\n\n\n\n\n\n" 
    

    for the action sheet. Magic I guess.