0
votes

I am trying to code different alertViews to pop up with different options depending on the image a user clicks on. My -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex method is saying I have an undeclared identifier of alertView. Any help would be appreciated. Some of my code is as follows:

@implementation Store


-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

UITouch *touch = [touches anyObject];

// SKINS SECTION -------------------------------------------------------------------------

if ([touch view] == catCover){
    catCover.image = [UIImage imageNamed:@"CatSelected.png"];
    dogCover.image = [UIImage imageNamed:@"DogCover.png"];
    markCover.image = [UIImage imageNamed:@"MarkCover.png"];
}else if([touch view] == dogCover){
    if (dogBought) {
        catCover.image = [UIImage imageNamed:@"CatCover.png"];
        dogCover.image = [UIImage imageNamed:@"DogSelected.png"];
        markCover.image = [UIImage imageNamed:@"MarkCover.png"];
    }else{
        //add code to pop up window asking if you want to buy or say you don't have enough cat cash

        if (totalCash >= 2000) {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Purchase" message:@"Are you sure you want to buy dog skins?" delegate:self cancelButtonTitle:@"Buy" otherButtonTitles:@"Cancel", nil];
            alert.tag = 10;
            [alert show];
        }else{
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Purchase" message:@"Sorry, but you don't have enough points to buy dog skins.  Keep playing!!" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"", nil];
            alert.tag = 11;
            [alert show];
        }

    }
}else if ([touch view] == markCover){
    if (markBought) {
        catCover.image = [UIImage imageNamed:@"CatCover.png"];
        dogCover.image = [UIImage imageNamed:@"DogCover.png"];
        markCover.image = [UIImage imageNamed:@"MarkSelected.png"];
    }else{
        //add code to pop up window asking if you want to buy or say you don't have enough cat cash
        if (totalCash >= 8000) {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Purchase" message:@"Are you sure you want to buy mark skins?" delegate:self cancelButtonTitle:@"Buy" otherButtonTitles:@"Cancel", nil];
            alert.tag = 20;
            [alert show];
        }else{
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Purchase" message:@"Sorry, but you don't have enough points to buy mark skins.  Keep playing!!" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"", nil];
            alert.tag = 21;
            [alert show];
        }
    }
}

// CATCHERS SECTION ----------------------------------------------------------------------

if ([touch view] == bucketCover) {
    bucketCover.image = [UIImage imageNamed:@"BucketSelected.png"];
    rosieCover.image = [UIImage imageNamed:@"rosieCover.png"];
}else if([touch view] == rosieCover){
    if (rosieBought) {
        bucketCover.image = [UIImage imageNamed:@"BucketCover.png"];
        rosieCover.image = [UIImage imageNamed:@"rosieSelected.png"];
    }else{
        //add code to pop up window asking if you want to buy or say you don't have enough cat cash
        if (totalCash >= 10000) {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Purchase" message:@"Are you sure you want to buy this catcher?" delegate:self cancelButtonTitle:@"Buy" otherButtonTitles:@"Cancel", nil];
            alert.tag = 30;
            [alert show];
        }else{
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Purchase" message:@"Sorry, but you don't have enough points to buy this catcher.  Keep playing!!" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"", nil];
            alert.tag = 31;
            [alert show];
    }
}

}



-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{

switch (alert.tag) {
    case 10:
        if (buttonIndex == 0){
            totalCash -= 2000;
            dogPrice.text = [NSString stringWithFormat:@"Purchased"];
            catCover.image = [UIImage imageNamed:@"CatCover.png"];
            dogCover.image = [UIImage imageNamed:@"DogSelected.png"];
            markCover.image = [UIImage imageNamed:@"MarkCover.png"];
            [self buyItem];
        }
        break;

    case 11:

        break;

    case 20:
        if (buttonIndex == 0){
            totalCash -= 8000;
            markPrice.text = [NSString stringWithFormat:@"Purchased"];
            catCover.image = [UIImage imageNamed:@"CatCover.png"];
            dogCover.image = [UIImage imageNamed:@"DogCover.png"];
            markCover.image = [UIImage imageNamed:@"MarkSelected.png"];
            [self buyItem];
        }
        break;

    case 21:

        break;

    case 30:
        if (buttonIndex == 0) {
            totalCash -= 10000;
            rosiePrice.text = [NSString stringWithFormat:@"Purchased"];
            bucketCover.image = [UIImage imageNamed:@"BucketCover.png"];
            rosieCover.image = [UIImage imageNamed:@"rosieSelected.png"];
            [self buyItem];
        }
        break;

    case 31:

        break;

    default:

        break;
}

}
3
What is the actual error message?Fred

3 Answers

0
votes

Change:

switch (alert.tag)

to

switch (alertView.tag)

0
votes

You're missing the closing brace on touchesBegan:withEvent:, so it thinks the following method declaration is part of that method body.

Using a standard indentation scheme that's supported by your tools can help with this. I just copied, pasted and reformatted the code and it jumped out immediately.

-1
votes

I don't see where the variable "alert" is declared. That's probably your undeclared identifier.