Using this for UIAlertView
- (void) alertStatus:(NSString *)msg :(NSString *)title :(int) tag
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title
message:msg
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil, nil];
alertView.tag = tag;
[alertView show];
}
But now UIAlertView get deprecated. change my code
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:msg preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* MyAlert = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
[alertController addAction:MyAlert];
[self presentViewController:alertController animated:YES completion:nil];
Here how can pass this tag value
alertView.tag = tag;
Help how to pass the tag value in UIAlertController. Thanks advance.
UIAlertController
is the UIViewController
, so we need to assign the tag for view, soe use alertController.view.tag
.
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"sds" message:@"sdf" preferredStyle:UIAlertControllerStyleAlert];
alertController.view.tag = tag;
UIAlertAction* MyAlert = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
[alertController addAction:MyAlert];
[self presentViewController:alertController animated:YES completion:nil];
update
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"sds" message:@"sdf" preferredStyle:UIAlertControllerStyleAlert];
alertController.view.tag = 3;
UIAlertAction* MyAlert = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action)
{
// OK button tappped.
[self dismissViewControllerAnimated:YES completion:^{
}];
}];
[alertController addAction:MyAlert];
[self presentViewController:alertController animated:YES completion:nil];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With