开发者

Way to force iOS action to wait until action before complete?

I have an iOS action开发者_如何学Python - (void)download; - which I have running at the launch of my iOS application.

However, I need another - (void)showData;- which displays data on a UIMapView to wait until all the data has been downloaded through - (void)download - before it begins. Just wondering if anyone knows a way to do that?

Thanks.


First send - (void)download; request and put a progress hud to the ui so user will know that you are downloading data, once you are done with download dismiss progress hud and run your - (void)showData; method

- (void)download{   
    NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0];
    NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
    if (connection) {
        receivedData = [[NSMutableData data] retain];
        //display loading hud here 
    } else {
        // oh noes!
    }
}

- (void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
    [receivedData setLength:0]; 
}

- (void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {   
    [receivedData appendData:data]; 
    int kb = [receivedData length] / 1024;
    //dismiss hud here 
    [self showData];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜