API からデータを読み込んでおり、UIProgressView を使用して読み込んだ量を表示しています。
私の viewWillAppear では、インターネット接続があることを確認するために Reachability を使用しています。次に、ある場合は、関数内で次の行が 10 回呼び出されます。
[self performSelectorInBackground:@selector(updateProgress) withObject:nil];
次に、このメソッドを実行します
-(void)updateProgress {
float currentProgress = myProgressBar.progress;
NSLog(@"%0.2f", currentProgress);
[loadingProg setProgress:currentProgress+0.1 animated:YES];
}
float は 0.1 ずつ増加し、ローディング ビューにこれが表示されます。
ビューが閉じられ (モーダル ビューです)、呼び出されると、メソッドが実行され、NSLog は currentProgress が必要に応じて増加していることを示します。ただし、進行状況バーは空のままです。誰がこれを引き起こす可能性があるか知っていますか?
参考までに、私はARCを使用しています。
アップデート:
これが私がAPIを呼び出す方法です
NSString *urlString = **url**;
NSURL *JSONURL = [NSURL URLWithString:urlString];
NSURLRequest *request = [NSURLRequest requestWithURL:JSONURL
cachePolicy:NSURLRequestReloadIgnoringCacheData
timeoutInterval:10];
if(connectionInProgress) {
[connectionInProgress cancel];
}
connectionInProgress = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
//This is where I call the update to the progress view
そして、私はこれらの機能を持っています:
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
JSONData = [NSMutableData data];
[JSONData setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[JSONData appendData:data];
}
-(void) connectionDidFinishLoading:(NSURLConnection *)connection
{
//add data to mutable array and other things
}