Search code examples
iosios6ios-simulator

Use of undeclared error :Alert error in ViewController.m in an iOS Application


An error is getting while doing code in my Application and the task is to redirect to url after alert. but about the code what I guess is correct. And here is my code

- (void) alertStatus:(NSString *)msg :(NSString *)title :(int)tag
{
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title
                                                       message:msg
                                                       delegate:self
                                               cancelButtonTitle:@"Ok"
                                              otherButtonTitles:nil, nil];
    if (tag) alert.tag = tag;
    {
    [alertView show];
    }
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if(alertView.tag == 101)
    {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"http://ABC.company.com"]];
        //[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
    }
}

the error is showing at the line

if (tag) alert.tag = tag;(Use of undeclared identifier:alert)

Solution

  • You have a couple of ...errors (omissions)

    • - (void) alertStatus:(NSString *)msg **withTitle**:(NSString *)title **andTag**:(int)tag
    • if (tag) alert.tag = tag; // but previously you declare alertView