我會演示我的問題是這樣的:我有一個項目與2類 - ViewController和GCManage。解僱GKGameCenterViewController
該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但它不會出現在任何情況下被調用。
現在當視圖控制器是委託並實現
- (void)gameCenterViewControllerDidFinish:(GKGameCenterViewController *)gameCenterViewController
{
[gameCenterViewController.presentingViewController dismissViewControllerAnimated:YES completion:^(void){}];
NSLog(@"Ran");
}
它運行完美。這裏發生了什麼事?
在GCManage.h中,你是否#import# 和'#import '?您說您的GCManage定義位於.h文件的第一行。 –
stevekohls
當然。我使用xcode創建並導入:#import #import @interface GCManage:NSObject –