xcode 无效的参数类型 void 到一元表达式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12076013/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 01:18:03  来源:igfitidea点击:

Invalid argument type void to unary expression

iphoneiosxcodealertvoid

提问by user1612646

Im currently making an app and am having some difficulty, here is the code:

我目前正在制作一个应用程序并且遇到了一些困难,这是代码:

-(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];

                   }



                   }



              }

My problem is that on the line: -(void) reportScore: (int64_t)............ it says "Invalid argument type void to unary expression"

我的问题是在线上:-(void) reportScore: (int64_t)............它说“无效的参数类型void到一元表达式”

Please help, Thanks.

请帮忙,谢谢。

采纳答案by glenn sayers

You're declaring methods inside another method, which you can't do. Declare all your methods separately, and call them where appropriate.

你在另一个方法中声明方法,这是你不能做的。分别声明所有方法,并在适当的地方调用它们。

- (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];
            }

 }