UIAlertController无法在iOS 9中运行

The*_*der 5 objective-c uialertview uialertcontroller ios9 xcode7

我添加了显示登录和密码文本字段的UIAlertController代码,它适用于iOS 8但在iOS 9中不起作用.文本字段缩小,如下图所示 在此输入图像描述

我正在尝试的代码如下:

 - (void)toggleLoginLdap:(UIViewController *)currentVC
 {

 if ([UIAlertController class])
        {


            self.alertController= [UIAlertController
                                       alertControllerWithTitle:@"Title of Msg"
                                       message:@"Hello"
                                       preferredStyle:UIAlertControllerStyleAlert];

            UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
                                                       handler:^(UIAlertAction * action){
                                                           NSString *userName = self.alertController.textFields[0].text;
                                                           NSString *password = self.alertController.textFields[1].text;



                                                       }];
            UIAlertAction* cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel
                                                           handler:^(UIAlertAction * action) {


                                                               [self.alertController dismissViewControllerAnimated:YES completion:nil];

                                                           }];


            [self.alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
                 textField.placeholder = @"Username/Email";
                 //textField.preservesSuperviewLayoutMargins = YES;
                textField.autoresizesSubviews = YES;
            }];
            [self.alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
                textField.placeholder = @"Password";
                textField.secureTextEntry = YES;
            }];
            //alertController.view.autoresizesSubviews = YES;
            [self.alertController addAction:ok];
            [self.alertController addAction:cancel];
            [currentVC presentViewController:self.alertController animated:YES completion:nil];
 }
Run Code Online (Sandbox Code Playgroud)

也尝试在rootviewcontroller上显示但没有运气,相同的代码适用于ios 8.项目已经过时并且得到了iOS 5的支持.任何帮助将不胜感激.谢谢.

sie*_*ian 1

在呈现alertController后添加[self.alertController.view layoutIfNeeded]我遇到了同样的问题并且它有效