ios - 调用 PerformSelector 的最佳方式 - iOS

标签 ios ios6 performselector

我正在调用使用不同时间戳调用 URL 的方法。然而,数据处理可能需要比我定义的时间更长的时间。

  [self performSelector:@selector(process) withObject:nil afterDelay:1.6];

下面部分显示了该方法的调用

 -(void)process
{
    timestamp=[NSString stringWithFormat:@"%1.f",progressValue];
    NSString *contour=@"&bandschema=4";
    NSString *url6=[NSString stringWithFormat:@"http://contour.php?  callback=contourData%@&type=json&timestamp=%@%@",timestamp,timestamp,contour];        
    NSURL *url1=[NSURL URLWithString:url6];
  __weak ASIHTTPRequest *request1 = [ASIHTTPRequest requestWithURL:url1];
        [request1 setCompletionBlock:^{
            responseString = [request1 responseString];
                [self plotPoint:self.responseString];

        }];
        [request1 setFailedBlock:^{

            NSError *error=[request1 error];
            NSLog(@"Error: %@", error.localizedDescription);
        }];
        [request1 startAsynchronous];
    }

这部分是分析数据的起点。

-(void)plotPoint:(NSString *)request
{
    NSArray *polygonArray = [[dict  objectForKey:@"data"]valueForKey:@"polygon"];
    NSArray *valleyPolygonArray = [[dict objectForKey:@"valley"]valueForKey:@"polygon"];
    CLLocationCoordinate2D *coords;
}

但是有时时间间隔不足以获取新数据,特别是当互联网连接不好时。

你能指导一下吗?我该如何处理这个问题?最优解是什么?

最佳答案

你能提供一些代码吗? 基本上,您需要在请求完成的委托(delegate)调用中执行操作

这里有更多信息: http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSURLConnection_Class/Reference/Reference.html

http://developer.apple.com/library/mac/#documentation/Foundation/Reference/NSURLConnectionDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intf/NSURLConnectionDelegate

编辑:
我还是不太明白,但看看这是否对你有帮助:

__weak ASIHTTPRequest *request1 = [ASIHTTPRequest requestWithURL:url1];  
        [request1 setCompletionBlock:^{  
            responseString = [request1 responseString];  
                [self plotPoint:self.responseString];  

        //if (something)  
            [self process];  
        }];

关于ios - 调用 PerformSelector 的最佳方式 - iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13353014/

相关文章:

ios - iOS中performSelector有什么用

ios - 它是否正确?使用 performSelector 而不是直接调用方法

ios - UILabel 将文本居中对齐

iphone - RightBarButtonItem 大写文本?

ios - ASIHTTPRequest POST 库

iphone - setAuthenticateHandler 无法通过 Game Center 进行身份验证

ios - 为什么我在执行 selector :withObject:@YES in iOS, 时总是得到 NO,这在 macOS 中是不同的?

objective-c - iOS ARC 不允许将 int 隐式转换为 NSNumber

objective-c - 在 IOS 中从应用程序上传到服务器

ios - 在ios上使用按钮旋转图像