【问题标题】:get response for particular asihttprequest获取特定 asihttprequest 的响应
【发布时间】:2011-06-20 08:28:11
【问题描述】:

我的问题如下:-我有多个 asihttprequests,甚至我不知道有多少,它就像动态的,在程序运行时我有 1 个纬度-logitude 的 latlongarray,它来自 web 服务,所以我不知道有多少纬度经度那里。然后我将执行 asihttprequest 以获取从用户位置到 latlongarray 中所有对象的距离。那么我如何识别在方法 didfinishresponse 为 asihttprequest 完成的请求:-

   for(int i=0,i<[latlongarray count],i++)
   if (![self queue]) {
      [self setQueue:[[[NSOperationQueue alloc] init] autorelease]];
   }


   NSURL *url = [NSURL URLWithString:@"url for getting distance"];
   ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
   [request setDelegate:self];
   [request setDidFinishSelector:@selector(requestDone:)];
   [request setDidFailSelector:@selector(requestWentWrong:)];
   [[self queue] addOperation:request]; //queue is an NSOperationQueue


- (void)requestDone:(ASIHTTPRequest *)request
{
   //I NEED TO DO SOMTHING HERE.
}

我已经与一些 5 或 6 个静态 asihttprequest 保持距离,但在这种情况下,我需要动态地做一些事情。我该怎么做?

感谢您的帮助!

【问题讨论】:

    标签: ios xcode ios4 iphone-sdk-3.0 asihttprequest


    【解决方案1】:

    您可以在创建请求时将信息存储在请求的“userInfo”字段中,然后可以在 requestDone 中使用:

    request.userInfo = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"value", @"key", nil];
    

    【讨论】:

      【解决方案2】:

      您可以使用整数值将tag 分配给请求。在requestDone中,您可以取回该值。

      request.tag = 1;

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-08-26
        • 2021-11-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多