0

I am showing pickerView on input field click it worked fine on other iOS but when I updated to iOS 8 it did not work. When i click on input field it does not show up the date picker.

Here is the code I am using.

- (void)textFieldDidBeginEditing:(UITextField *)aTextField{

     appDelegate.recentAddSowID = @"";

     if (aTextField == dateTextField) {
     [dateTextField resignFirstResponder];

     pickerViewPopup = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"" destructiveButtonTitle:nil otherButtonTitles:nil];

     pickerView = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 44, 0, 0)];
     pickerView.datePickerMode=UIDatePickerModeDate;

     pickerView.hidden = NO;
     pickerView.date = [NSDate date];

     UIToolbar *pickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
     pickerToolbar.barStyle = UIBarStyleBlackOpaque;
     [pickerToolbar sizeToFit];

     NSMutableArray *barItems = [[NSMutableArray alloc] init];

      UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
     [barItems addObject:flexSpace];

      UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneButtonPressed:)];
      [barItems addObject:doneBtn];

      UIBarButtonItem *cancelBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelButtonPressed:)];
      [barItems addObject:cancelBtn];

       [pickerToolbar setItems:barItems animated:YES];

       [pickerViewPopup addSubview:pickerToolbar];
       [pickerViewPopup addSubview:pickerView];

       [pickerView addTarget:self action:@selector(updateTextField:) forControlEvents:UIControlEventValueChanged];

       [dateTextField setInputView:pickerView];

       [pickerViewPopup showInView:self.view];
       [pickerViewPopup setBounds:CGRectMake(0,0,320, 464)];
    }
}

I am testing on iPhone 5S.

Shanti K
  • 2,793
  • 1
  • 14
  • 31

1 Answers1

0

They changed the implementation of UIActionSheet in iOS 8. You can no longer add views to its view hierarchy

The documentation (https://developer.apple.com/library/ios/documentation/uikit/Reference/UIActionSheet_Class/index.html) states:

UIActionSheet is not designed to be subclassed, nor should you add views to its hierarchy. If you need to present a sheet with more customization than provided by the UIActionSheet API, you can create your own and present it modally with presentViewController:animated:completion:.

Also, the UIActionSheet is deprecated in iOS 8

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.

As an alternative, try this: https://github.com/skywinder/ActionSheetPicker-3.0. It works with iOS 8 and might be what you need

Source: Add UIPickerView in UIActionSheet from IOS 8 not working

Community
  • 1
  • 1
anthonyliao
  • 1,284
  • 1
  • 8
  • 8