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
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.
add [self.alertController.view layoutIfNeeded]
after presenting alertController
I had the same problem and it worked
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With