我将像这样演示我的问题:我有一个包含 2 个类的项目 - ViewController 和 GCManage。
ViewController 是UIViewController
GCManage 的子类NSObject
。
当我在 ViewController 中按下按钮时,它会调用此方法:
-(IBAction)showLeaderboards:(id)sender{
GCManage *manageGC = [[GCManage alloc] init];
if (manageGC.isGCenabled == YES){
GKGameCenterViewController *gameCenterController = [[GKGameCenterViewController alloc] init];
if (gameCenterController != nil)
{
gameCenterController.gameCenterDelegate = manageGC;
gameCenterController.viewState = GKGameCenterViewControllerStateLeaderboards;
[self presentViewController:gameCenterController animated:YES completion:nil];
}
}
}
对于这种情况,假设isGCenabled = YES
.
现在 GCManage 界面是
@interface GCManage : NSObject <GKGameCenterControllerDelegate>
(在 h 文件中,第一行)。
我已经实施
- (void)gameCenterViewControllerDidFinish:(GKGameCenterViewController *)gameCenterViewController
{
[gameCenterViewController.presentingViewController dismissViewControllerAnimated:YES completion:^(void){}];
[gameCenterViewController.presentedViewController dismissViewControllerAnimated:YES completion:^(void){}];
[gameCenterViewController dismissViewControllerAnimated:YES completion:^(void){}];
NSLog(@"Ran");
}
在 GCManage 中,但在任何情况下似乎都没有调用它。
现在当 ViewController 是代表并实现时
- (void)gameCenterViewControllerDidFinish:(GKGameCenterViewController *)gameCenterViewController
{
[gameCenterViewController.presentingViewController dismissViewControllerAnimated:YES completion:^(void){}];
NSLog(@"Ran");
}
它运行完美。这里发生了什么事?