copyWithZone-unrecognized选择器发送到实例

时间:2013-02-25 13:30:53

标签: objective-c

我使用以下代码实例化视图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

需要更多帮助......

2 个答案:

答案 0 :(得分:6)

财产:

@property (nonatomic, copy) GKSession *currentSession;

错了。 GKSession不是可复制对象。所以你应该通过保留:

来获取它的引用
@property (nonatomic, retain) GKSession *currentSession;

答案 1 :(得分:0)

您的自定义类GK会话必须是NSObject的子类,并且您最好实现在协议NSCopy中声明的方法