Webサービスからデータをロードする小さなiPhoneアプリがあります。データの読み込み中に問題が発生しないことを確認するために、アプリ上に半透明のビューを作成し、CFRunloopRun()を使用して、すべてのデータがバックグラウンドで読み込まれるまで待機します。これはそのためのコードです:
self.connection = [[[NSURLConnection alloc] initWithRequest:request delegate:self] autorelease];
// Now show an animation
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
UIView *window = [[UIApplication sharedApplication] keyWindow];
UIView *shield = [[UIView alloc] initWithFrame:window.bounds];
shield.backgroundColor = [UIColor blackColor];
shield.alpha = 0.5f;
[window addSubview:shield];
spinner.center = shield.center;
[shield addSubview:spinner];
spinner.hidden = NO;
NSLog( @"JCL.callServerWithRequest(), spinner view: %@, shield view: %@, window: %@", spinner, shield, window );
[spinner startAnimating];
// Hand over to the Runnloop to wait
CFRunLoopRun();
[spinner stopAnimating];
[spinner removeFromSuperview];
[spinner release];
[shield removeFromSuperview];
[shield release];
これは正常に機能しますが、ロード後にどこかのボタンのクリックが再生されるため、ユーザーがダウンロードボタンを2回クリックすると、ダウンロードも2回実行されます。
シールドが削除される前にUIイベントを消費する方法についてのアイデア。
ありがとう-アンディ