I have a old Xcode project that is targeted for iOS 6 and higher. I recently opened it up in Xcode 6 and ran in iPhone 6 simulator for iOS 8. When I tried this action
UIAlertView* dialog = [[UIAlertView alloc] initWithTitle:@"Enter Folder Name" message:@"Keep it short and sweet" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil]; dialog.alertViewStyle = UIAlertViewStylePlainTextInput; dialog.tag = 400; [dialog show];
I get a pop-up window but when I click on the text field, no keyboard comes up. I googled and read that I need to use UIAlertController instead. Since I need to support iOS 6, 7 versions as well so I changed my code like this.
if ([UIAlertController class]) { // use UIAlertController UIAlertController *alert= [UIAlertController alertControllerWithTitle:@"Enter Folder Name" message:@"Keep it short and sweet" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action){ //Do Some action here UITextField *textField = alert.textFields[0]; NSLog(@"text was %@", textField.text); }]; UIAlertAction* cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { NSLog(@"cancel btn"); [alert dismissViewControllerAnimated:YES completion:nil]; }]; [alert addAction:ok]; [alert addAction:cancel]; [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) { textField.placeholder = @"folder name"; textField.keyboardType = UIKeyboardTypeDefault; }]; [self presentViewController:alert animated:YES completion:nil]; } else { // use UIAlertView UIAlertView* dialog = [[UIAlertView alloc] initWithTitle:@"Enter Folder Name" message:@"Keep it short and sweet" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil]; dialog.alertViewStyle = UIAlertViewStylePlainTextInput; dialog.tag = 400; [dialog show]; }
Again if I try the same action NO keyboard is displayed.
Is this a bug in Xcode 6 simulator or I am doing something wrong?