我使用以下代码实例化视图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
你能帮忙吗?
提前致谢!
答案 0 :(得分:6)
@property (nonatomic, copy) GKSession *currentSession;
错了。 GKSession不是可复制的对象。所以你应该通过保留:
来获取它的引用@property (nonatomic, retain) GKSession *currentSession;