Добавить процесс загрузки NSURLConnection в UIProgressView

Я создал UIProgressView . Но я использовал процесс NSTimer для UIProgressView . Теперь мне нужно интегрировать процесс UIProgressView при загрузке URL. Размер UIProgressView будет зависеть от данных NSURLConnection.

Я использовал следующий код для NSURLConnection .

-(void)load {
    NSURL *myURL = [NSURL URLWithString:@"http://feeds.epicurious.com/newrecipes"];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:myURL
                                                           cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
                                                       timeoutInterval:60];

    [[NSURLConnection alloc] initWithRequest:request delegate:self];
}

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
    responseData = [[NSMutableData alloc] init];
}


-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    [responseData appendData:data];
}

-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
    [connection release];

    UIAlertView *alert = [[UIAlertView alloc] init];
    [alert setTitle:@"Warning"];
    [alert setMessage:@"Network Connection Failed?"];
    [alert setDelegate:self];
    [alert addButtonWithTitle:@"Yes"];

    [alert show];
    [alert release];

    NSLog(@"Error");
}

-(void)connectionDidFinishLoading:(NSURLConnection *)connection 
{
    responsetext = [[[NSString alloc] initWithData:responseData encoding: NSASCIIStringEncoding] autorelease];
}
5
задан halfer 17 November 2017 в 20:17
поделиться