无法从Sprite Kit打开游戏中心

时间:2014-09-13 21:34:18

标签: ios objective-c xcode uiviewcontroller sprite-kit

我想从我的Sprite Kit类打开Game Center Leaderboards页面,但我一直收到此错误:

2014-09-13 14:24:52.183 SpriteTest[6733:77452]-[UIView setIgnoresSiblingOrder:]:   
unrecognized selector sent to instance 0x7f89cf078fd0
2014-09-13 14:24:52.218 SpriteTest[6733:77452] *** Terminating app due to 
uncaught exception 'NSInvalidArgumentException', reason: '-[UIView 
setIgnoresSiblingOrder:]: unrecognized selector sent to instance 0x7f89cf078fd0'

这就是我尝试从我的SKScene课程中打开排行榜的方式:

- (void)openGameCenter{
    if ([GKLocalPlayer localPlayer].isAuthenticated) {
        GKGameCenterViewController *leaderboardController = [[GKGameCenterViewController alloc] init];
        leaderboardController.gameCenterDelegate = self;
        leaderboardController.viewState = GKGameCenterViewControllerStateLeaderboards;
        UIViewController *vc = [[GameViewController alloc] init];
        [vc presentViewController: leaderboardController animated: YES completion:nil];
    }else{
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle: @"Error"
            message: @"You must be logged into Game Center to view the leaderboards. Open Game Center?"
            delegate: self
            cancelButtonTitle:@"No"
            otherButtonTitles:@"Yes",nil];
        [alert show];
    }
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 1) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"gamecenter:"]];
    }
}

GameViewController是呈现此精灵工具包的ViewController。

1 个答案:

答案 0 :(得分:1)

抛出异常是因为您正在向UIView的实例而不是其子类SKView发送消息。 SKView理解setIgnoresSiblingOrder:,但UIView不理解。

尝试此解决方案:https://stackoverflow.com/a/19889592/3367343