我正在制作应用程序并遇到一些困难,这是代码:
-(void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)ButtonIndex {
if (ButtonIndex == 1) {
- (void) reportScore: (int64_t) score forCategory: (NSString*) category
{
GKScore *scoreReporter = [[[GKScore alloc] initWithCategory:@"123"] autorelease];
scoreReporter.value = score;
[scoreReporter reportScoreWithCompletionHandler:^(NSError *error) {
if (error != nil)
{
// handle the reporting error
}
}];
else if (ButtonIndex==2){
- (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];
}
}
}
我的问题在于: - (void)reportScore:(int64_t)............ 它说“无效的参数类型无效到一元表达式”
请帮助,谢谢。
答案 0 :(得分:3)
你在另一个方法中声明方法,你不能这样做。分别声明所有方法,并在适当的时候调用它们。
- (void) reportScore: (int64_t) score forCategory: (NSString*) category
{
GKScore *scoreReporter = [[[GKScore alloc] initWithCategory:@"123"] autorelease];
scoreReporter.value = score;
[scoreReporter reportScoreWithCompletionHandler:^(NSError *error) {
if (error != nil)
{
// handle the reporting error
}
}];
}
- (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];
}
-(void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)ButtonIndex {
if (ButtonIndex == 1)
{
[self reportScore:score forCategory:cat];
}
else if (ButtonIndex==2)
{
[self showLeaderboard];
}
}