Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIAlertController how add the tag value in obj c

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.

like image 585
saravanar Avatar asked Jan 30 '17 08:01

saravanar


1 Answers

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];
like image 131
Anbu.Karthik Avatar answered Oct 15 '22 18:10

Anbu.Karthik