警报视图和游戏中心选项出错

时间:2012-08-21 23:59:58

标签: iphone gamekit

我正在制作和应用,并且遇到了以下代码的错误:

NSString *timemessage = [NSString stringWithFormat:@"Unlucky! You survived for %i seconds!", timenumber];
UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:@"You've Been Caught!" message:timemessage delegate:nil cancelButtonTitle:@"Try Again" otherButtonTitles:@"Show Leaderboard", @"Submit To Game Center",nil];
[alert1 show];

-(void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)ButtonIndex {
    NSString *buttonTitle = [alertView buttonTitleAtIndex:ButtonIndex];
    if ([buttonTitle isEqualToString:@"Submit To Game Center"]) {
        - (void) reportScore: (int64_t) score forCategory: (NSString*) category
        {
            GKScore *scoreReporter = [[[GKScore alloc] initWithCategory:@"*****"] autorelease];
            scoreReporter.value = score;
            [scoreReporter reportScoreWithCompletionHandler:^(NSError *error) {
                if (error != nil)
                {
                    // handle the reporting error
                }
            }];
        }
    }
    else if ([buttonTitle isEqualToString:@"Show Leaderboard"]){
        - (void) showLeaderboard:
        {
            GKLeaderboardViewController *leaderboardController = [[GKLeaderboardViewController alloc] init];
            if (leaderboardController != nil)
            {
                leaderboardController.leaderboardDelegate = self;
                [self presentModalViewController: leaderboardController animated: YES];
            }
        }
    }
}
-(void) leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)viewController{
    [self dismissModalViewControllerAnimated:YES];
} 

所以我面临的问题是:

  1. 这些按钮不适用于警报,它们什么都不做。
  2. “一元表达式”
  3. 出现错误“无效的参数类型”void“

    我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

我确信第一个问题出在警报代表身上。

UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:@"You've Been Caught!" message:timemessage delegate:self cancelButtonTitle:@"Try Again" otherButtonTitles:@"Show Leaderboard", @"Submit To Game Center",nil];
[alert1 show];

请参阅委托人:自我