5
votes

I have added the UIAlertController code showing login and password textfields, it works for iOS 8 but in iOS 9 not works. The textfields shrinks as shown in figure below enter image description here

The code I am trying is as follows :

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

Also tried to show on rootviewcontroller but no luck , same code works on ios 8. Project is old and having support from iOS 5. Any help will be appreciated. Thanks.

2
so the textfields should be in vertical layout or horizontal layout ?Teja Nandamuri
I just tried your code. It works fine. where are you calling this method toggleLoginLdap ?Teja Nandamuri
Horizontal layout(One another below) , And it also works for me in new demo project but its not working in my old project (which is created in previous version of xcode).The iCoder
toggleLoginLdap called from another viewController .The iCoder
please post the mehtod, where you are calling this. Might be you should call this on main thread!!!Teja Nandamuri

2 Answers

1
votes

add [self.alertController.view layoutIfNeeded] after presenting alertController I had the same problem and it worked

0
votes

I know this question is old but I've been researching this for more than a day.

I stumbled upon a thread in the Pixate freestyle github. My problem was that we were using Pixate Freestyle pod

If you take your code and put it in a clean Xcode project, it will look fine. There was a workaround mentioned there; but it's in swift. I'll try to find it and post a link when I do.

EDIT: https://github.com/Pixate/pixate-freestyle-ios/issues/178