如何将其他参数传递给ASIHTTPRequest didFinishSelector选择器

时间:2011-09-12 04:35:07

标签: objective-c ios asihttprequest

我正在使用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回调吗?

1 个答案:

答案 0 :(得分:4)

您可以通过填充NSDictionary并将其设置为请求的userInfo属性来传递对象。