2

我正在使用以下代码来实例化视图 SenderPlayerViewController 并传递对象“会话”:

- (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 回答