我正在尝试编写不同的alertViews,以根据用户点击的图像弹出不同的选项。我的 - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex方法是说我有一个未声明的alertView标识符。任何帮助,将不胜感激。我的一些代码如下:
@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;
}
}
答案 0 :(得分:0)
变化:
switch (alert.tag)
到
switch (alertView.tag)
答案 1 :(得分:0)
您错过了touchesBegan:withEvent:
上的右括号,因此它认为以下方法声明是该方法体的一部分。
使用您的工具支持的标准缩进方案可以帮助解决此问题。我只是复制,粘贴并重新格式化代码,它立即跳出来。
答案 2 :(得分:-1)
我没有看到声明变量“alert”的位置。这可能是你未申报的标识符。