Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIDatePicker is not visible in iOS 8

Tags:

ios8

I have an issue with date picker, i.e. UIDatePicker is working fine in all version except iOS 8.

Code:

UIDatePicker *datePicker = [[UIDatePicker alloc]init];
    [datePicker setDate:[NSDate date]];
    [datePicker setDatePickerMode:UIDatePickerModeDate];
    datePicker.maximumDate=[NSDate date];
    [datePicker addTarget:self action:@selector(updateBirthdateField:) forControlEvents:UIControlEventValueChanged];
    [birthdatField setInputView:datePicker];
like image 720
Praveenkumar_Contus Avatar asked Jul 10 '14 09:07

Praveenkumar_Contus


3 Answers

This turned out to be a Simulator issue for me in Xcode 6.0.1. This worked on device (iPhone 4S with iOS 8 release version). As described by the previous user, the steps below made the date picker visible on an iOS 8 simulator for me.

  • Launch the simulator and the app and click on the field that has the date picker as the input view.

  • Now press CMD+K (Hardware->Keyboard->Toggle Software Keyboard) and the date picker became visible.

Again this was a simulator only issue and the issue did not occur on device.

like image 114
kalyanbk Avatar answered Nov 29 '22 11:11

kalyanbk


I was seeing same problem with iOS simulator - worked in iOS 7, but not iOS 8. To fix problem, select the Hardware menu for iOS Simulator, then select Keyboard -> Toggle Software Keyboard.

like image 28
user4059289 Avatar answered Nov 29 '22 11:11

user4059289


I too faced this problem, now i solved this by the following two different methods:

1). Instead of UIActionSheet, i used a customised UIView. Just added the date Pickers to the view and presented and dismissed. Also refer this SWActionSheet.

2). I have checked the conditions that if OS version is greater than 8.0, if NO i used UIActionSheet and else UIAlertViewController. Added the picker controller as subview.

id ageActionSheet;

    if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0"))
    {
        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:@"" preferredStyle:UIAlertControllerStyleActionSheet];

        UIAlertAction *alertAction = [UIAlertAction actionWithTitle:@"" style:UIAlertActionStyleDefault handler:nil];
        [alertController addAction:alertAction];
        [alertController addAction:alertAction];
        [alertController addAction:alertAction];
        [alertController addAction:alertAction];

        ageToolbar.frame = CGRectMake(-8,0, 320, 45);
        ageTitleLbl.frame = CGRectMake(50, 3, 200, 40);
        picker.frame = CGRectMake(-20, 45, 360, frame.size.height - 50 );

        [alertController.view addSubview:ageToolbar];
        [alertController.view addSubview:ageTitleLbl];
        [alertController.view addSubview:picker];

        ageActionSheet = alertController;
    }
    else
    {
        ageActionSheet = [[UIActionSheet alloc]initWithTitle:nil delegate:nil cancelButtonTitle:@"" destructiveButtonTitle:nil otherButtonTitles: nil];
        [ageActionSheet addSubview:ageToolbar];
        [ageActionSheet addSubview:ageTitleLbl];
        [ageActionSheet addSubview:picker];
        [ageActionSheet sizeToFit];
    }
like image 45
Muruganandham K Avatar answered Nov 29 '22 13:11

Muruganandham K