2

次のコードを使用してビュー SenderPlayerViewController をインスタンス化し、オブジェクト "session" を渡します。

- (void)session:(GKSession *)session peer:(NSString *)peerID didChangeState: GKPeerConnectionState)state {
switch (state) {
    case GKPeerStateConnected:
        NSLog(@"Connected Central");
        if ([settings.playerType isEqualToString:@"SENDER"]){                 
            SenderPlayerViewController *myViewController = [[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:NULL] instantiateViewControllerWithIdentifier:@"SenderPlayerViewController"];
            [self.navigationController pushViewController:myViewController animated:YES];
            myViewController.currentSession=session;

        }

        break;            
    case GKPeerStateDisconnected:
        NSLog(@"Disconnected Central");
        self.currentSession = nil;
        break;
}   
}

ビュー SenderPlayerViewController のヘッダー ファイルは次のとおりです。

@interface CentralViewController : UIViewController {
Settings *settings;}
@property (nonatomic, copy) GKSession *currentSession;

@end       

コードが実行されると、次のエラーが発生します。

[GKSession copyWithZone:]: unrecognized selector sent to instance 0x9661200

助けてください!

前もって感謝します!

4

1 に答える 1

6
@property (nonatomic, copy) GKSession *currentSession;

間違っている。GKSession はコピー可能なオブジェクトではありません。したがって、保持して参照を取得する必要があります。

@property (nonatomic, retain) GKSession *currentSession;
于 2012-04-30T19:45:29.450 に答える