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 UIAlertController 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.
để trường văn bản có bố cục dọc hoặc bố cục ngang không? –
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? –
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). –