iPhoneアプリで初めて2つのスレッドを使用していますが、問題が発生しました。このプロトタイプには、ローカルWebページをロードするViewControllerがあります。ページの読み込みが完了するまでアクティビティインジケーターを表示したい。以下のコードを使用すると、アクティビティインジケーターが起動し、ページが正しく読み込まれますが、アクティビティインジケーターが停止または非表示になることはありません。「loading」関数が呼び出されるようには見えません。
私は何が間違っているのですか?
- (void)viewDidLoad {
[self.view addSubview:activityIndicator];
[activityIndicator startAnimating];
[NSThread detachNewThreadSelector:@selector(getData) toTarget:self withObject:nil];
[super viewDidLoad];
}
- (void)getData {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[detailWebView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"page1" ofType:@"html"]isDirectory:NO]]];
[NSTimer scheduledTimerWithTimeInterval: (1.0/2.0) target:self selector:@selector(loading) userInfo:nil repeats:YES];
[pool release];
}
- (void)loading {
if(!detailWebView.loading){
[activityIndicator stopAnimating];
[activityIndicator removeFromSuperview];
}