UIAlertController no es jerarquía de windows

Estoy tratando de mostrar una UIPickerView emergente que contiene un UIPickerView y UITextField .

A continuación se muestra mi código que utilizo para crear el pop-up.

 self.alert = [UIAlertController alertControllerWithTitle:nil message:@"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" prefernetworkingStyle:UIAlertControllerStyleAlert]; CGRect pickerFrame = CGRectMake(0, 0, 270, 200); UIPickerView *regionsPicker = [[UIPickerView alloc] initWithFrame:pickerFrame]; regionsPicker.tag = 1; regionsPicker.dataSource = (id <UIPickerViewDataSource>)self; regionsPicker.delegate = (id <UIPickerViewDelegate>) self; [regionsPicker setShowsSelectionIndicator:YES]; UIView *toolView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 270.0f, 44.f)]; toolView.backgroundColor = [UIColor blackColor]; CGRect buttonFrame = CGRectMake(0, 5, 100, 30); UIButton *button = [[UIButton alloc] initWithFrame: buttonFrame]; button.imageEdgeInsets = UIEdgeInsetsMake(0, button.titleLabel.frame.size.width, 0, -button.titleLabel.frame.size.width); UIImage *btnImage = [UIImage imageNamed:@"delete.png"]; [button setImage:btnImage forState:UIControlStateNormal]; [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [button setTitleColor: [UIColor blueColor] forState: UIControlStateNormal]; [toolView addSubview:button]; [button addTarget:self action:@selector(closeDialog:) forControlEvents:UIControlEventTouchUpInside]; self.textField = [[UITextView alloc] initWithFrame:CGRectMake(30, 170, 220, 200)]; _textField.editable = NO; _textField.hidden=true; self.textField.text = @"Enter text..."; self.textField.font = [UIFont systemFontOfSize:15]; self.textField.autocorrectionType = UITextAutocorrectionTypeNo; self.textField.keyboardType = UIKeyboardTypeDefault; self.textField.returnKeyType = UIReturnKeyDone; self.textField.textColor = [UIColor lightGrayColor]; self.textField.delegate = (id <UITextViewDelegate>) self; self.textField.layer.borderWidth = 1.0f; self.textField.layer.cornerRadius = 5; self.textField.layer.borderColor = [[UIColor grayColor] CGColor]; [toolView addSubview:self.textField]; CGRect actionFrame = CGRectMake(80, 400, 100, 30); UIButton *actionBtn = [[UIButton alloc] initWithFrame: actionFrame]; [actionBtn setTitle:@"Submit" forState:UIControlStateNormal]; [actionBtn setTitleColor: [UIColor whiteColor] forState: UIControlStateNormal]; [actionBtn setBackgroundColor:[UIColor purpleColor]]; [self.textField setUserInteractionEnabled:YES]; [toolView setUserInteractionEnabled:YES]; [self.alert.view setUserInteractionEnabled:YES]; [self.alert.view addSubview:regionsPicker]; [self.alert.view addSubview:self.textField]; [self.alert.view addSubview:toolView]; [self.alert.view addSubview:actionBtn]; id rootViewController=[UIApplication shanetworkingApplication].delegate.window.rootViewController; if([rootViewController isKindOfClass:[UINavigationController class]]) { rootViewController=[((UINavigationController *)rootViewController).viewControllers objectAtIndex:0]; } [rootViewController presentViewController:_alert animated:YES completion:nil]; 

Funciona bien. Sin embargo, si estoy intentando ingresar text en UITextField , el keyboard no aparece y, por lo tanto, no puedo escribir nada dentro del UITextField . ¿Cómo puedo resolver esto?

la razón es que ha agregado textField , button , todos los que están dentro de la vista de herramientas, pero la altura de la vista de toolview es muy inferior

cambie la altura de su toolView de 44 a 500 o de lo contrario (combinación de campo de text, button + 50). Cambiar a continuación la statement

 UIView *toolView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 270.0f, 44.f)]; 

a

  UIView *toolView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 270.0f, 500.f)]; 

Actualizar

cambiar esta línea

  [self presentViewController:alert animated:YES completion:nil]; 

dentro

  id rootViewController=[UIApplication shanetworkingApplication].delegate.window.rootViewController; if([rootViewController isKindOfClass:[UINavigationController class]]) { rootViewController=[((UINavigationController *)rootViewController).viewControllers objectAtIndex:0]; } [rootViewController presentViewController:alert animated:YES completion:nil]; 

Actualizar nuevo

  UIViewController *rootViewController=[UIApplication shanetworkingApplication].delegate.window.rootViewController; if([rootViewController isKindOfClass:[UINavigationController class]]) { rootViewController=[((UINavigationController *)rootViewController).viewControllers objectAtIndex:0]; }else { while (rootViewController.presentedViewController) { rootViewController = rootViewController.presentedViewController; } } [rootViewController presentViewController:alert animated:YES completion:nil]; 

Rápido

  var rootViewController: UIViewController = UIApplication.shanetworkingApplication().delegate.window.rootViewController if (rootViewController is UINavigationController.self) { rootViewController = ((rootViewController as! UINavigationController)).viewControllers[0] } else { while rootViewController.presentedViewController { rootViewController = rootViewController.presentedViewController } } rootViewController.presentViewController(alert, animated: true, completion: { _ in }) 

Intente esto puede ayudarlo:

 UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:@" Your message " prefernetworkingStyle:UIAlertControllerStyleAlert]; UIView *toolView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 270, 200)]; toolView.backgroundColor = [UIColor blackColor]; CGRect buttonFrame = CGRectMake(0, 5, 100, 30); UIButton *button = [[UIButton alloc] initWithFrame:buttonFrame]; [button setTitle:@"Image" forState:UIControlStateNormal]; [button setTitleColor:[UIColor blueColor] forState:UIControlStateNormal]; [toolView addSubview:button]; UITextField *txtField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 270, 44)]; txtField.borderStyle = UITextBorderStyleRoundedRect; txtField.backgroundColor = [UIColor grayColor]; txtField.font = [UIFont systemFontOfSize:15]; txtField.placeholder = @"enter text"; txtField.autocorrectionType = UITextAutocorrectionTypeNo; txtField.keyboardType = UIKeyboardTypeDefault; txtField.returnKeyType = UIReturnKeyDone; txtField.clearButtonMode = UITextFieldViewModeWhileEditing; txtField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; txtField.delegate = (id<UITextFieldDelegate>)self; [toolView addSubview:txtField]; [txtField setUserInteractionEnabled:YES]; [toolView setUserInteractionEnabled:YES]; [alertController.view setUserInteractionEnabled:YES]; [alertController.view addSubview:toolView]; [self presentViewController:alertController animated:YES completion:nil];