2015-09-24 34 views
5

Tôi đã thêm mã UIAlertController hiển thị trường văn bản đăng nhập và mật khẩu, nó hoạt động cho iOS 8 nhưng trong iOS 9 không hoạt động. Các textfields co lại như thể hiện trong hình bên dưới enter image description hereUIAlertController không hoạt động trong iOS 9

Mã tôi đang cố gắng thực hiện như sau:

- (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]; 
} 

Cũng cố gắng để hiển thị trên rootviewcontroller nhưng không có may mắn, cùng một mã hoạt động trên ios 8. Dự án là cũ và có hỗ trợ từ iOS 5. Mọi trợ giúp sẽ được đánh giá cao. Cảm ơn.

+0

để trường văn bản có bố cục dọc hoặc bố cục ngang không? –

+1

Tôi vừa thử mã của bạn. Nó hoạt động tốt. bạn đang gọi phương thức này ở đâu toggleLoginLdap? –

+0

Bố cục nằm ngang (Một bên dưới), Và nó cũng hoạt động cho tôi trong dự án demo mới nhưng nó không hoạt động trong dự án cũ của tôi (được tạo trong phiên bản trước của xcode). –

Trả lời

1

thêm [self.alertController.view layoutIfNeeded] sau khi trình bày alertController tôi đã cùng một vấn đề và nó làm việc

+1

Không hiệu quả với tôi. –

0

Tôi biết câu hỏi này là cũ nhưng tôi đã nghiên cứu này trong hơn một ngày.

Tôi tình cờ gặp một chuỗi trong github tự do Pixate. Vấn đề của tôi là chúng tôi đã sử dụng Pixate Freestyle pod

Nếu bạn lấy mã của mình và đặt nó vào một dự án Xcode sạch sẽ, nó sẽ ổn. Có một cách giải quyết được đề cập ở đó; nhưng nó nhanh chóng. Tôi sẽ cố gắng tìm và đăng liên kết khi tôi làm.

CHỈNH SỬA: https://github.com/Pixate/pixate-freestyle-ios/issues/178

Các vấn đề liên quan