1

I have searched and cannot find an answer to my problem.

I am using the following code to popup a UIDatePicker when entering a UITextField. It works perfectly on iPhone.

mySheet = [[UIActionSheet alloc] initWithTitle:nil delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
[mySheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];

CGRect pickerFrame = CGRectMake(0, 44, 0, 0);

UIDatePicker *datePicker = [[UIDatePicker alloc] initWithFrame:pickerFrame];
[datePicker setDatePickerMode:UIDatePickerModeTime];

if (whatPressed == 1) {
    [datePicker setDate:startDate];
}
else
{
    [datePicker setDate:endDate];
}


[mySheet addSubview:datePicker];

UIToolbar *controlToolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, mySheet.bounds.size.width, 44)];
[controlToolBar setBarStyle:UIBarStyleBlack];
[controlToolBar sizeToFit];

UIBarButtonItem *spacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *setButton = [[UIBarButtonItem alloc] initWithTitle:@"Set" style:UIBarButtonItemStyleDone target:self action:@selector(dismissDate)];
UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonItemStyleBordered target:self action:@selector(cancelDate)];

[controlToolBar setItems:[NSArray arrayWithObjects:spacer, cancelButton, setButton, nil] animated:NO];
[mySheet addSubview:controlToolBar];

[mySheet showInView:self.view];

[mySheet setBounds:CGRectMake(0, 0, 320, 485)];

I am now trying to use the same code for the iPad version and the view appears but it is not high enough. I have tried changing the CGRect values but they don't seem to have any effect.

The view appears to be the width of an iPhone, and about 1cm in height. Confused.

Help appreciated.

Tony
  • 2,335
  • 21
  • 25
  • 1
    The method `showFromRect:inView:animated:` is a better choice for the iPad. – Kevin Grant Jul 03 '12 at 01:51
  • Thanks @KevinGrant I'll give that a go and get back to you – Tony Jul 03 '12 at 06:19
  • I tried numerous methods to display this UIDatePicker. In the end I have given up and used the iPad's large screen to display the UIDatePicker directly. Thanks anyway ... this is very strange behaviour though and I hope someone knows a fix – Tony Jul 03 '12 at 20:12
  • I am also stuck in this Problem – Anju Jul 13 '12 at 11:19
  • I too have this, anyone find a solution? – sradforth Jan 20 '13 at 14:57
  • Same issue here. I ended up having to scrap the idea of a UIActionSheet and went with a UIPopoverController. I have a UIViewController with a UIDatePicker and UIButton as its subviews and it has the same outcome I was looking for. – Nigel Greens Apps May 14 '13 at 08:32
  • Anyone brought this up on Apple Support/Community? Also, found this workaround: http://stackoverflow.com/questions/7974475/uiactionsheet-on-ipad-frame-too-small – Guven Sep 01 '13 at 12:44

0 Answers0