通常,Xcode 中的自动完成功能会自动完成该类的方法名称,如果该类位于其他对象的委托(delegate)中,则方法名称如下:
@interface ViewController : UIViewController <UIAlertViewDelegate,
GKPeerPickerControllerDelegate>
但是对于 Game Kit 的方法,要在
ViewController.m
里面:- (void) receiveData:(NSData *)data fromPeer:(NSString *)peer
inSession: (GKSession *)session context:(void *)context {
// ...
}
它似乎不是任何委托(delegate)方法的一部分,无论是通过 Xcode 的自动完成还是在任何文档中?如果它不是委托(delegate)的一部分,为什么它与所有其他委托(delegate)方法的工作方式不同?
更新:如果我搜索所有头文件:
grep -r receiveData /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk
包含该行的唯一文件是:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk/System/Library/Frameworks/GameKit.framework/Headers/GKSession.h:- (void)setDataReceiveHandler:(id)handler withContext:(void *)context; // SEL = -receiveData:fromPeer:inSession:context:
所以它只出现在评论中......
最佳答案
setDataReceiveHandler:withContext:
的文档GKSession
中的方法类 说:
The handler must implement a method with the following signature:
- (void) receiveData:(NSData *)data fromPeer:(NSString *)peer inSession: (GKSession *)session context:(void *)context;
这并不能回答您为什么没有像普通委托(delegate)方法那样实现此方法的问题。我想这个实现提供了更大的灵 active ,因为你可以让一个对象响应
GKSession
。管理连接的委托(delegate)方法,同时指定一个不同的对象在建立连接后处理传入的数据。无论如何,希望这能回答这个方法在哪里定义的实际问题,这让我摸不着头脑。
关于iphone - 在 iOS Game Kit 中,是接收数据 :fromPeer:inSession:context part of a delegate protocol?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12334194/