Search code examples
objective-cipadios4uipickerviewuiactionsheet

UIDatePicker on a UIActionSheet not working with ipad 4.3


I've been digging through the forum and can't find the answer to this so I'm posting. I have several apps that use a UIActionSheet with a UIPickerView or a UIDatePickerView on them to prompt the user for inputs. These inputs are for configuration values. So the prompt comes up on top of a popover for ipad.

This code works great on ipad and iphone 5, and iphone 4.3 loves it too. ipad 4.3 doesn't work at all. The behavior is odd. The PickerView either doesn't appear (with just headings at top like "Hour" and "Min"). Or it appears as a 10 pixel wide block on the left side without being able to interact with it or use it.

Screenshots and code below. Any ideas? The code below generates the first screenshots appearance. The first screenshots code is virtually identical but with a UIPickerView These were taken from the simulator, but I've had users report the same problem on their physical devices.

Thanks in advance - Kevin

popover with just headings

popover with side widget oddity

// create enough space for the UIPicker to show up above the selection button
NSString *title = @"\n\n\n\n\n\n\n\n\n\n\n\n";
if ((UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation)) && 
    (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPad)) {
    title = @"\n\n\n\n\n\n\n\n\n";
}


UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:title delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:NSLocalizedString(@"Choose", @"Click to finilize Value - Timer"), nil];
[actionSheet showInView:self.view];

UIDatePicker *pickerView = [[UIDatePicker alloc] init];
[pickerView setDatePickerMode: UIDatePickerModeCountDownTimer];
if (timerInterval == 0) timerInterval = 5;
[pickerView setMinuteInterval: timerInterval];
[pickerView setCountDownDuration: [timerRec.timerDuration intValue]];
[actionSheet addSubview:pickerView];

Solution

  • UIActionSheets are only meant for buttons. Even though they work on iPhone with adding a date picker, they don't work on iPad. You will need to create a custom view or display your view in a popOver if you want to continue using the action sheet to hold the datePicker.

    I ran into this same issue.