gpt4 book ai didi

objective-c - 为什么 UIAlertView 会有所不同?

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:24:27 24 4
gpt4 key购买 nike

我有以下有效的代码:

// Load new game screen
-(IBAction)newGame_button:(id)sender {
myAlert = [[UIAlertView alloc]
initWithTitle:@"Varning"
message:@"Om du går vidare kommer pågående spel stoppas och nollställas!"
delegate:self
cancelButtonTitle:@"Tillbaka"
otherButtonTitles:@"Fortsätt", nil];
myAlert.tag=kTagNewGame;
[myAlert show];
[myAlert release];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
switch(myAlert.tag ) {
case kTagContinueGame:
NSLog(@"kTagContinueGame");
NSMutableArray *continueGameArray = [[NSMutableArray alloc] initWithCapacity:0];

AccessCurrentGameData *getCurrentGameInfo = [AccessCurrentGameData new];
continueGameArray = [getCurrentGameInfo continueTheCurrentGame];
[getCurrentGameInfo release];
[continueGameArray retain];
[continueGameArray release];

QandA_ViewController * temp = [[QandA_ViewController alloc] init];
[self setQanda_ViewController:temp];
[temp release];
[[self navigationController] pushViewController:qanda_ViewController animated:YES];
break;
case kTagNewGame:
NSLog(@"kTagNewGame");
AccessCurrentGameData *zeroCurrentGameFileFunction = [AccessCurrentGameData new];
[zeroCurrentGameFileFunction firstCreationOrRestoreOfGameDataFile];
[zeroCurrentGameFileFunction release];

NewGameViewController * temp2 = [[NewGameViewController alloc] init];
[self setNewGameViewController:temp2];
[temp2 release];
[[self navigationController] pushViewController:newGameViewController animated:YES];
break;
default:
break;
}
}

但是,当我删除 NSLog 时,出现以下错误:

Expected expression before 'NSMutableArray'

我不明白为什么会这样。我可能可以离开 NSLog,但为什么呢?

最佳答案

问题是变量声明不能直接跟在 case 标签后面。为了解决这个问题,我通常将整个 case block 放在 {} 中:

...
case kTagNewGame:
{
AccessCurrentGameData *zeroCurrentGameFileFunction = [AccessCurrentGameData new];
[zeroCurrentGameFileFunction firstCreationOrRestoreOfGameDataFile];
[zeroCurrentGameFileFunction release];

NewGameViewController * temp2 = [[NewGameViewController alloc] init];
[self setNewGameViewController:temp2];
[temp2 release];
[[self navigationController] pushViewController:newGameViewController animated:YES];
break;
}
...

关于objective-c - 为什么 UIAlertView 会有所不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5133838/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com