2012-12-29 52 views
0

我有同樣的問題,在這個線程:What causes "Missed Method" in this code?這段代碼#2中的「錯過的方法」是什麼原因?

但我不明白如何解決這個問題,或者如果它甚至是一個問題。

我正在做的書「開始iOS遊戲中心和遊戲工具包」中的教程,並得到這個問題。我確實總是得到「......錯過的方法」,並試圖理解爲什麼,但不幸的是我沒有。我也嘗試在上面的線程上使用答案,但無濟於事。

我非常感謝這一個幫助。

的代碼我使用目前:

#import "GameCenterManager.h" 

@implementation GameCenterManager 

@synthesize delegate; 

+(BOOL)isGameCenterAvailable { 
Class gcClass = (NSClassFromString(@"GKLocalPlayer")); 

NSString *reqSysVer = @"4.1"; 
NSString *currSysVer = [[UIDevice currentDevice]systemVersion]; 

BOOL osVersionSupported = ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending); 

return (gcClass && osVersionSupported); 
} 

-(void)retrieveFriendsList { 

if ([GKLocalPlayer localPlayer].authenticated == YES) { 
    [[GKLocalPlayer localPlayer]loadFriendsWithCompletionHandler:^(NSArray *friends, NSError *error) { 
     [self callDelegateOnMainThread:@selector(friendsFinishLoading:error:) withArg:friends error:error]; 
    }]; 
} else { 
    NSLog(@"...You must authenticate first"); 
} 
} 

-(void)authenticateLocalUser { 

if ([GKLocalPlayer localPlayer].authenticated) { 
    return; 
} 

[[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:^(NSError *error){ 
    [self callDelegateOnMainThread:@selector(processGameCenterAuthentication:) withArg:NULL error: error]; 
}]; 
} 

-(void)callDelegateOnMainThread:(SEL)selector withArg: (id) arg error:(NSError*) err { 
dispatch_async(dispatch_get_main_queue(), ^(void) { 
    [self callDelegate:selector withArg: arg error: err]; 
}); 
} 

-(void)callDelegate: (SEL) selector withArg: (id) arg error: (NSError*) err { 
assert([NSThread isMainThread]); 

if ([delegate respondsToSelector: selector]) { 
    if(arg != NULL) { 
     [delegate performSelector: selector withObject: arg withObject: err]; 

    } else { 
     [delegate performSelector: selector withObject: err]; 
    } 
} else { 
    NSLog(@"...Missed Method"); 
} 
} 

輸出,GC授權之後:

...Missed Method 

回答

0

您的代碼調用[self callDelegateOnMainThread:@selector(processGameCenterAuthentication:) withArg:NULL error: error];其在檢查閹類實現的方法(callDelegate:withArg:error:)結束了processGameCenterAuthentication:方法。你得到Missed Method輸出,因爲你似乎沒有實現它。

+0

我確實調用了方法,但是我確實發現該方法被執行了兩次,並且這是第二次「...錯過方法」。 – PeterK

+0

我確實發現了這個問題,它在選擇器中調用「friendsFinishedLoading」時出現拼寫錯誤(在上面的代碼中)「friendsFinishLoading」。我是這樣一個n00b :-(但是,非常感謝JustSid帶領我走上了正確的軌道。 – PeterK

相關問題