1

I'm new to iOS and working this DatePicker for the first time. I'm trying to show a date picker inside a UIActionSheet. I got this code from other StackOver flow topics

- (void)showDatePicker:(UITapGestureRecognizer *)recognizer {
    NSLog(@"label touched");
    UIActionSheet *menu = [[UIActionSheet alloc] initWithTitle:@"Date Picker"
                                                      delegate:self
                                             cancelButtonTitle:@"Cancel"
                                        destructiveButtonTitle:nil
                                             otherButtonTitles:@"OK",nil];
    // Add the picker
    UIDatePicker *pickerView = [[UIDatePicker alloc] init];
    pickerView.datePickerMode = UIDatePickerModeTime;
    [menu addSubview:pickerView];
    [menu showInView:self.view];
    
    CGRect menuRect = menu.frame;
    CGFloat orgHeight = menuRect.size.height;
    menuRect.origin.y -= 214; //height of picker
    menuRect.size.height = orgHeight+214;
    menu.frame = menuRect;
    
    
    CGRect pickerRect = pickerView.frame;
    pickerRect.origin.y = orgHeight;
    pickerView.frame = pickerRect;
    
    //[pickerView release];
    //[menu release];
}

but the DatePicker is not showing. This is what I get.

enter image description here

What am I doing wrong here?

Community
  • 1
  • 1
Drunken Daddy
  • 7,326
  • 14
  • 70
  • 104

1 Answers1

2

According to Apple docs

Important: UIActionSheet is deprecated in iOS 8. (Note that UIActionSheetDelegate is also deprecated.) To create and manage action sheets in iOS 8 and later, instead use UIAlertController with a preferredStyle of UIAlertControllerStyleActionSheet.

or you can add datePicker as an inputView to the Textfield. (Just use UITextfield instead of UIButton to open the picker)

UIDatePicker *datepicker = [[UIDatePicker alloc] initWithFrame:CGRectZero];
[datepicker setDatePickerMode:UIDatePickerModeDate];
myTextField.inputView = datepicker;
nilam_mande
  • 931
  • 7
  • 14