Hi guys,
As we all know that from iOS8 Apple has provided a new UIAlertController class which you can use instead of UIAlertView which is now deprecated. So today i'll demonstrate, how to use UIAlertController for displaying an alert in iOS. Here are two simple steps that are declaration & calling it easy to use.
Here we are defining alert controller along with the message that it will display & the "OK" button which we use to remove alert once popped.
-(void)alertAction:(NSString *)title message:(NSString *)message {
UIAlertController * alert = [UIAlertController
alertControllerWithTitle:title
message:message
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* ok = [UIAlertAction
actionWithTitle:@"OK"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
[alert dismissViewControllerAnimated:YES completion:nil];
}];
[alert addAction:ok];
[self presentViewController:alert animated:YES completion:nil];
}
And now all we have to do is call the above function wherever u need the alert popup as-
[self alertAction:@"Your message that you Want to display at the title of alert we generally use app Name" message:@"Actual message that you want to notify the user"];
Thanks for reading, hope it helps.
0 Comment(s)