0

我想viewController为我的游戏设置匹配。为此,我将GKMatchmakerViewControllerDelegate委托添加到我的 mainUIViewControllerHome,使其看起来像:

class Home: UIViewController, GKGameCenterControllerDelegate, GKMatchmakerViewControllerDelegate {

要加载配对界面,我使用以下代码:

func openMatchmaker() {
    var gcViewController: GKMatchmakerViewController = GKMatchmakerViewController(rootViewController: self)

    gcViewController.matchmakerDelegate = self

    gcViewController.hosted = false
    gcViewController.matchRequest.minPlayers = 2
    gcViewController.matchRequest.maxPlayers = 2
    gcViewController.matchRequest.defaultNumberOfPlayers = 2

    self.showViewController(gcViewController, sender: self)
    self.navigationController?.pushViewController(gcViewController, animated: true)
}

class Home: ...但是,当我尝试运行代码时,我收到以下错误。错误消息说:

 Type 'Home' does not conform to protocol `GKMatchmakerViewControllerDelegate`. 

为什么会这样?

4

2 回答 2

1

大多数情况下,您收到该错误是因为您没有实现特定协议所需的功能。您可以通过单击该协议的命令来查看它们。添加以下方法:

func matchmakerViewController(viewController: GKMatchmakerViewController!,
    didFailWithError error: NSError!) {
}

func matchmakerViewController(viewController: GKMatchmakerViewController!,
    didFindHostedPlayers players: [AnyObject]!) {
}

func matchmakerViewControllerWasCancelled(viewController: GKMatchmakerViewController!) {
}

func matchmakerViewController(viewController: GKMatchmakerViewController!,
    hostedPlayerDidAccept player: GKPlayer!) {
}
于 2015-02-14T14:58:49.180 回答
0

已批准答案中的第二个功能已在最新的 SDK 中更新:

func matchmakerViewController(viewController: GKMatchmakerViewController, didFindHostedPlayers players: [GKPlayer]) {
   ... 
}
于 2015-09-22T17:59:35.137 回答