Подтвердить что ты не робот

IOS 8: UIAlertView/UIAlertController, не отображающий текст или кнопки

У меня есть UIAlertView, который отлично отображается в iOS 7, но в iOS 8 он не показывает никаких кнопок или ярлыков. Предупреждение по-прежнему видно, но только маленькая белая коробка. Кнопки "ОК" и "Отмена" также принимают свои события, но не отображаются тексты.

Я использовал это предупреждение для показа по щелчку кнопки

- (IBAction)sel_btnLogout:(id)sender {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Logout!" message:@"Are you sure you want to logout?" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];
    [alert show];
}

Я проверил фрейм в iOS 8: он дает (0,0,0,0), но в iOS 7 он дает определенное значение.

Я также проверил для итерации в subviews uialertview. В iOS7 он идет в цикле, поскольку он обнаруживает оповещения о бдительности. В iOS8 говорится, что нет никаких подзонов alertView.

4b9b3361

Ответ 1

Я получил ответ на свой вопрос. Проблема заключалась в том, что я использовал модель UIFont + Replacement в своем проекте. Это отлично работало на iOS 7, но на iOS 8 использовалось несколько устаревших методов. Из-за этого я не знаю, почему, но только мое предупреждение не показывало никаких ярлыков.

Решение. Удалил категорию из проекта и установил шрифт через xib. Когда мы помещаем файл .tff любого шрифта в рабочую область проекта, мы видим эти имена шрифтов в xib под пользовательскими шрифтами. НЕТ НУЖНО ИСПОЛЬЗОВАТЬ UIFont + Категория замены.

Ответ 2

Проверьте, доступен ли класс

if ([UIAlertController class])
{

    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Alert title" message:@"Alert message" preferredStyle:UIAlertControllerStyleAlert];

    UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
    [alertController addAction:ok];

    [self presentViewController:alertController animated:YES completion:nil];

} 
else 
{

    UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"Alert title" message:@"Alert message" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];

    [alert show];

}

Ответ 3

С iOS 8 вы можете установить заголовок вместо сообщения:

[[[UIAlertView alloc] initWithTitle:@"AlertView in iOS 8." message:nil delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]show];

UIAlertView устарел от iOS 8 для получения дополнительной информации.

http://nshipster.com/uialertcontroller/. https://developer.apple.com/LIBRARY/IOS/documentation/UIKit/Reference/UIAlertViewDelegate_Protocol/index.html

Итак, если вы собираетесь писать отдельный код для iOS 7 и iOS 8, вместо этого вы должны использовать UIAlertController:

UIAlertController *alertController = [UIAlertController  alertControllerWithTitle:@"AlertView in iOS 8"  message:nil  preferredStyle:UIAlertControllerStyleAlert];
[alertController addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
 [self dismissViewControllerAnimated:YES completion:nil];
}]];
[self presentViewController:alertController animated:YES completion:nil];

Ответ 4

Прочитайте приведенный ниже код, чтобы понять, как добавлять поля и кнопки к предупреждениям.

- (IBAction)UIAlertControllerWithActionSheetTextFields:(id)sender {
    UIAlertController * alert=   [UIAlertController
                                  alertControllerWithTitle:@"Info"
                                  message:@"You are using UIAlertController with Actionsheet and text fields"
                                  preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction* ok = [UIAlertAction
                         actionWithTitle:@"OK"
                         style:UIAlertActionStyleDefault
                         handler:^(UIAlertAction * action)
                         {
                             NSLog(@"Resolving UIAlert Action for tapping OK Button");
                             [alert dismissViewControllerAnimated:YES completion:nil];
                             
                         }];
    UIAlertAction* cancel = [UIAlertAction
                             actionWithTitle:@"Cancel"
                             style:UIAlertActionStyleDefault
                             handler:^(UIAlertAction * action)
                             {
                                 NSLog(@"Resolving UIAlertActionController for tapping cancel button");
                                 [alert dismissViewControllerAnimated:YES completion:nil];
                                 
                             }];
    
    [alert addAction:ok];
    [alert addAction:cancel];
    
    [alert addTextFieldWithConfigurationHandler:^(UITextField * textField) {
       textField.accessibilityIdentifier = @"usernameTextField";
        textField.placeholder = @"Enter your username";
        textField.accessibilityLabel = @"usernameLabel";
    }];
    
    [alert addTextFieldWithConfigurationHandler:^(UITextField * textField) {
       textField.placeholder = @"Enter your password";
       textField.accessibilityIdentifier = @"paswordTextField";
       textField.accessibilityLabel = @"passwordLabel";
    }];
    
    [self presentViewController:alert animated:YES completion:nil];
    
}

Ответ 5

в iOS 8 вам нужно заменить UIAletrview и UIActionSheet на UIAlertcontroller. Сначала вы читаете эту документацию на форуме Apple

Apple Alertcontroller

Ответ 6

Вы можете проверить этот код

if (([[[UIDevice currentDevice] systemVersion] compare:@"8.0" options:NSNumericSearch] == NSOrderedAscending))
{
    // use UIAlertView
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:Title message:desc delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
    [alert show];
}
else {
    // use UIAlertController
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:Title message:desc preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

    }];
    [alert addAction:okAction];
    [self presentViewController:alert animated:YES completion:nil];
}

Ответ 7

let alert = UIAlertController(title: "Warning" as String , message: messageString as String, preferredStyle: .Alert)
        let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.Default)
        {
            UIAlertAction in
                self.dismissViewControllerAnimated(true, completion: nil)
        }
        // Add the actions
        alert.addAction(okAction)
        self.presentViewController(alert, animated: true, completion: nil)

Ответ 8

Я думаю, что это не проблема UIAlertview. пожалуйста, проверьте эту работу хорошо..

Я думаю, что ваши проблемы с кодом...........

в любом view controller введите этот код в viewDidLoad Как показано ниже:

- (void)viewDidLoad 
{
    [super viewDidLoad];

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"My message" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];
    [alert show];
}