如何将附加参数传递给 ASIHTTPRequest didFinishSelector 选择器
我使用 ASIHTTPRequest 为我们的其余 api 构建 api。
Api 将所有请求包装到它自己的方法中。
- (void) foo:(id)caller
andSuccessCallback:(SEL)successCallback
andFailureCallback:(SEL)failureCallback {
_currentCaller=caller;
_currentSuccessCallback=successCallback;
_currentFailureCallback=failureCallback;
NSString *urlString = @"http://localhost/foo";
NSURL *url= [NSURL URLWithString: urlString];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDelegate:self];
[request setDidFinishSelector:@selector(fooSuccess:)];
[request startAsynchronous];
}
- (void) fooSuccess:(ASIHTTPRequest *)request {
if (statusCode >=400) {
if ([_currentCaller respondsToSelector:_currentFailureCallback])
[_currentCaller performSelector:_currentFailureCallback withObject:statusCode withObject:message];
} else {
if ([_currentCaller respondsToSelector:_currentSuccessCallback])
[_currentCaller performSelector:_currentSuccessCallback];
}
[request release];
}
目前,为了传递回调选择器,我使用类私有变量 _currentCaller _currentSuccessCallback _currentFailureCallback=failureCallback
我可以将它们直接传递给 fooSuccess 回调吗?
Im building api for our rest api using ASIHTTPRequest.
Api wraps all requests to its own methods.
- (void) foo:(id)caller
andSuccessCallback:(SEL)successCallback
andFailureCallback:(SEL)failureCallback {
_currentCaller=caller;
_currentSuccessCallback=successCallback;
_currentFailureCallback=failureCallback;
NSString *urlString = @"http://localhost/foo";
NSURL *url= [NSURL URLWithString: urlString];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDelegate:self];
[request setDidFinishSelector:@selector(fooSuccess:)];
[request startAsynchronous];
}
- (void) fooSuccess:(ASIHTTPRequest *)request {
if (statusCode >=400) {
if ([_currentCaller respondsToSelector:_currentFailureCallback])
[_currentCaller performSelector:_currentFailureCallback withObject:statusCode withObject:message];
} else {
if ([_currentCaller respondsToSelector:_currentSuccessCallback])
[_currentCaller performSelector:_currentSuccessCallback];
}
[request release];
}
Currently to pass callback selector I use class private variables _currentCaller _currentSuccessCallback _currentFailureCallback=failureCallback
Can i pass them to fooSuccess callback directly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过填充 NSDictionary 并将其设置为请求的 userInfo 属性来传递对象。
You can pass objects by populating a NSDictionary and setting it as the request's userInfo property.