The below method is to show an Alert in a ViewController Wherever you want an alert you can call this method (if you implement it globally then no need to implement in every ViewController).
call this method like, [self showAlert];
-(void) showAlert {
UIAlertController *warningAlertController = [UIAlertController alertControllerWithTitle:@"Title Of your Alert" message:@"Here enter your alert message !" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *alertAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
// After click on Ok what you want to perform you can write here
}];
[warningAlertController addAction:alertAction];
[self presentViewController:warningAlertController animated:YES completion:nil];
}
And if you want add few more actions you can add to it as shown below,
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
// After click on Cancel what you want to perform you can write here
}];
[warningAlertController addAction:cancelAction];
No comments:
Post a Comment