0

它是如何做到的,我不需要将数据对象放在选择器调用方法中?

带有警告的代码(本地数据声明):

NSDictionary *data = [NSDictionary dictionaryWithObjectsAndKeys:@"SiluetaImage", @"ACTION", silueta_id, @"siluetaid", siluetaTyp_id, @"siluetatypid", nil];
[self performSelector:@selector(downloadBinDataForTyp:data:) 
           withObject:@"SiluetaImage" 
           withObject:data];

没有警告的代码:

[self performSelector:@selector(downloadBinDataForTyp:data:) 
           withObject:@"SiluetaImage" 
           withObject:[NSDictionary dictionaryWithObjectsAndKeys:@"SiluetaImage", @"ACTION", silueta_id, @"siluetaid", siluetaTyp_id, @"siluetatypid", nil]];

选择器:

- (void)downloadBinDataForTyp:(NSString *)typ data:(NSDictionary*)data
{
    ASINetworkQueue *q = [self queue];
    NSString *sUrl = @"url_web_service";

    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:sUrl]];
    NSString *msgLength = [NSString stringWithFormat:@"%d", [[self getMsg] length]];

    [request setTimeOutSeconds:60];
    [request addRequestHeader: @"Content-Type" value:@"text/xml; charset=utf-8"];
    [request addRequestHeader: @"SOAPAction" value:_action];
    [request addRequestHeader: @"Content-Length" value:msgLength];
    [request setRequestMethod: @"POST"];
    request.userInfo = data;

    [request appendPostData:[self getMsg]];
    [request setDelegate:self];

    [q addOperation:request];
    [q go];

}
4

1 回答 1

1
NSDictionary *data = [NSDictionary dictionaryWithObjectsAndKeys:@"SiluetaImage", @"ACTION", silueta_id, @"siluetaid", siluetaTyp_id, @"siluetatypid", nil];
[self performSelector:@selector(downloadBinDataForTyp:data:) 
           withObject:@"SiluetaImage" 
           withObject:data];

在此,您将data其范围仅传递给该方法。并且在方法之外无法访问它,因为它正在获取released。

于 2013-02-21T10:23:44.477 回答