如果同时在两个UIViewController中调用[[RKClient sharedClient] get @“ foo.xml”委托:自我],那会是什么?我有什么问题吗?
viewController_A
{
[[RKClient sharedClient] get:@"foo.xml" delegate:self];
}
viewController_B
{
[[RKClient sharedClient] get:@"foo.xml" delegate:self];
}
最佳答案
如果您查看get:delegate:
的RKClient实现,只需执行此操作
- (RKRequest *)get:(NSString *)resourcePath delegate:(id)delegate {
return [self load:resourcePath method:RKRequestMethodGET params:nil delegate:delegate];
}
而
load:method:params:delegate:
的实现是- (RKRequest *)load:(NSString *)resourcePath method:(RKRequestMethod)method params:(NSObject<RKRequestSerializable> *)params delegate:(id)delegate {
NSURL* resourcePathURL = nil;
if (method == RKRequestMethodGET) {
resourcePathURL = [self URLForResourcePath:resourcePath queryParams:(NSDictionary*)params];
} else {
resourcePathURL = [self URLForResourcePath:resourcePath];
}
RKRequest *request = [[RKRequest alloc] initWithURL:resourcePathURL delegate:delegate];
[self setupRequest:request];
[request autorelease];
request.method = method;
if (method != RKRequestMethodGET) {
request.params = params;
}
[request send];
return request;
}
它不使用任何RKClient状态/共享数据,因此不会出现问题。方法get:delegate:本身是异步的,因此无论如何这些事情都会在后台发生。
关于ios - 如果同时在两个UIViewControllers中调用[[RKClient sharedClient] get @“foo.xml”委托(delegate):自我],那将会是什么?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8193089/