简体   繁体   English

Swift-类型'MenuViewController'不符合协议'GKGameCenterControllerDelegate'

[英]Swift - Type 'MenuViewController' does not conform to protocol 'GKGameCenterControllerDelegate'

I am trying to use GameCenter to show the leaderboards for the high scores in my game. 我正在尝试使用GameCenter来显示我游戏中的高分排行榜。 I have been trying to use some code to implement GameCenter but it all fails. 我一直在尝试使用一些代码来实现GameCenter,但这一切都失败了。

I'm told to set gameCenterDelegate before the GameCenter view controller is shown. 我被告知要在显示GameCenter视图控制器之前设置gameCenterDelegate。

I've been told to do it like this: 有人告诉我这样做:

var gcViewController: GKGameCenterViewController = GKGameCenterViewController()
gcViewController.gameCenterDelegate = self

but this gives me the following error: 但这给了我以下错误:

Type 'MenuViewController' does not conform to protocol 'GKGameCenterControllerDelegate'

I tried changing this: 我尝试更改此:

class MenuViewController: UIViewController {

to: 至:

class MenuViewController: GKGameCenterViewControllerDelegate {

but this gives me loads of errors, the first of which being on this line, reading: 但这给了我很多错误,第一个出现在该行上,显示为:

Use of undeclared type 'GKGameCenterViewControllerDelegate'

I have been trying to get this to work for about a fortnight, and there seems to be no solution anywhere. 我一直在努力使其工作约两周,而且似乎无处可寻。 Can someone please help me??? 有人可以帮帮我吗???

Your MenuViewController needs to be both a subclass of UIViewController and to declare that it implements the delegate. 您的MenuViewController必须既是UIViewController的子类, 必须声明它实现了委托。 If you've imported GameKit correctly, then: 如果您已正确导入GameKit,则:

class MenuViewController: UIViewController, GKGameCenterControllerDelegate {
   ...
}

should work. 应该管用。 I agree that the syntax is a bit confusing, with no demarkation between the superclass and the implemented protocols. 我同意语法有点混乱,在超类和已实现的协议之间没有描述。

Edit: Whoops, simple error. 编辑:糟糕,简单的错误。 The delegate is actually GKGameCenterControllerDelegate not GKGameCenterViewControllerDelegate . 委托实际上是GKGameCenterControllerDelegate而不是GKGameCenterViewControllerDelegate Declare that you implement it as above, then actually implement the methods. 声明您按上述方法实施,然后实际实施方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我该怎么办? 在SpriteKit中迅速说:类型'GameScene'不符合协议'GKGameCenterControllerDelegate'? - What should I do? In SpriteKit swift it says: Type 'GameScene' does not conform to protocol 'GKGameCenterControllerDelegate'? 类型不符合协议Swift - Type does not conform to protocol Swift Swift - 类型“*”不符合协议“*” - Swift - Type '*' does not conform to protocol '*' Swift-类型'CircularTransition'不符合协议'UIViewControllerAnimatedTransitioning' - Swift - Type 'CircularTransition' does not conform to protocol 'UIViewControllerAnimatedTransitioning' Swift - MultipeerConnectivity类型不符合协议 - Swift - MultipeerConnectivity Type does not conform to protocol Swift - 结构类型不符合协议 - Swift - struct type does not conform to protocol 类型不符合协议序列类型 - Swift - type does not conform to protocol Sequence Type - Swift 类型“NSPersistentStore”在swift中不符合协议“BooleanType” - Type 'NSPersistentStore' does not conform to protocol 'BooleanType' in swift Swift:类型'ViewController'不符合协议'UIPageViewControllerDataSource' - Swift: Type 'ViewController' does not conform to protocol 'UIPageViewControllerDataSource' Swift 2.0类型'()'不符合协议 - Swift 2.0 Type '()' does not conform to protocol
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM