Я хорошо знаю, что подобные вопросы существуют, но я думаю, что не смог найти правильное решение этой проблемы.Как правильно убрать UIAlertController как с помощью кнопки, так и нажимать на нее?
Если вы могли бы просто взглянуть на код ниже, вы можете сказать, что в этом нет ничего плохого. BUT,
Если я собираюсь отобразить UIAlertController на UIViewController, который вызывается из раскадровки по следующему коду, с помощью кнопки контроллера предупреждения отклоняет первый UIAlertController, а затем мой UIViewController. Поэтому я вернусь к своему первоначальному контроллеру.
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"MyViewController"];
[vc setModalPresentationStyle:UIModalPresentationFullScreen];
[self presentViewController:vc animated:NO completion:NULL];
А вот код для UIAlertController:
- (IBAction)myAlertAction:(id)sender {
UIAlertController *controller = [UIAlertController alertControllerWithTitle:@"Title"
message:@"Lorem ipsum dolor sit amet"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *alertAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
[controller addAction:alertAction];
[self presentViewController:controller animated:YES completion:^{
controller.view.superview.userInteractionEnabled = YES;
[controller.view.superview addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget: self action: @selector(alertControllerBackgroundTapped)]];
}];
}
- (void)alertControllerBackgroundTapped
{
[self dismissViewControllerAnimated: YES
completion: nil];
}
Как я могу это исправить?
UIAlertController * контроллер объявляет globlly, а затем выполнить операцию –
ваш код является правильным. вам не нужно объявлять контроллер UIAlertController * глобально. в вашем коде есть и другие проблемы. –
@balkaransingh, я прошу отличаться. Я только что открыл еще один проект в xcode и снова проверил его. Результат такой же –