0

Я хочу представить UIAlertController с UIAlertControllerStyleAlert стилем, увольнением UIAlertController с UIAlertControllerStyleActionSheet стиля. Другими словами, я хочу представить alertview после выбора опции из листа действий. Но ни alertview не представлено, только это сообщение в журнале появляется:Present UIAlertController в другой UIAlertController причине При попытке загрузить вид контроллера представления во время его deallocating не допускается

Попытка загрузить вид контроллера представления в то время как он deallocating не допускается и может привести к непредсказуемому поведению

Здесь мой код:

UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:@"MyApp" message:@"Info" preferredStyle:UIAlertControllerStyleActionSheet]; 

    [actionSheet addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { 

     // Cancel button tappped. 
     [self dismissViewControllerAnimated:YES completion:^{ 
     }]; 
    }]]; 

    [actionSheet addAction:[UIAlertAction actionWithTitle:@"Credits" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { 

     UIAlertController * alert= [UIAlertController 
             alertControllerWithTitle:@"Credits" 
             message:@"Here some text in the alertview..." 
             preferredStyle:UIAlertControllerStyleAlert]; 

     UIAlertAction* yesButton = [UIAlertAction 
            actionWithTitle:@"Close" 
            style:UIAlertActionStyleDefault 
            handler:^(UIAlertAction * action) 
            { 
             //Handel your yes please button action here 


            }]; 

     [alert addAction:yesButton]; 

     [self dismissViewControllerAnimated:YES completion:^{ 
      // try to present the alertview 
      [self presentViewController:alert animated:YES completion:nil]; 
     }]; 
    }]]; 

    // Present action sheet. 
    [self presentViewController:actionSheet animated:YES completion:nil]; 

Рабочий лист работает, предупреждение нет. Таблица действий представлена ​​с UITableViewController. Каждая помощь с благодарностью, заблаговременно

ответ

1

Исправлена. Код. Вам не нужно увольнять, чтобы загрузить AlertController.

UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:@"MyApp" message:@"Info" preferredStyle:UIAlertControllerStyleActionSheet]; 

[actionSheet addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { 

    // Cancel button tappped. 
    [self dismissViewControllerAnimated:YES completion:^{ 
    }]; 
}]]; 

[actionSheet addAction:[UIAlertAction actionWithTitle:@"Credits" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { 

    UIAlertController * alert= [UIAlertController 
            alertControllerWithTitle:@"Credits" 
            message:@"Here some text in the alertview..." 
            preferredStyle:UIAlertControllerStyleAlert]; 

    UIAlertAction* yesButton = [UIAlertAction 
           actionWithTitle:@"Close" 
           style:UIAlertActionStyleDefault 
           handler:^(UIAlertAction * action) 
           { 
            //Handel your yes please button action here 


           }]; 

    [alert addAction:yesButton]; 

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

// Present action sheet. 
[self presentViewController:actionSheet animated:YES completion:nil]; 

Только что попробовал, что на пустой проект, добавив, что код - (пустоте) viewDidAppear: (BOOL) анимированные и работает отлично.

Надежда, что помогает

+0

Какая глупая ошибка, которую я совершил ... спасибо! Спасибо также @Mike Taverna – Kurtis92

2

Проблема заключается в том вы вызываете [само] presentViewController в завершение блока [самоуправления dismissViewControllerAnimated].

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