To build a typical alert, we need a title, a message, and one or more action buttons. Each action button has a block of code that runs when the user presses the button.
As an example, let's study a helper method that displays an error popup with an OK button. When the user presses the OK button, the alert will be dismissed and the app will stop its busy mode. Here is the implementation:
- (void)showSaveImageFailureAlertWithMessage:(NSString *)message { UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Failed to save image" message:message preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction* okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { [self stopBusyMode]; }]; [alert addAction:okAction]; [self presentViewController:alert animated:YES completion:nil]; }