0

特定のデータをダウンロードします。ダウンロードすると、このメソッドが呼び出されます。

- (void)connectionDidFinishLoading:(NSURLConnection *)connection;

このメソッドでは、View Controller に回転イメージを提示する必要があります。これはデリゲートで行い、データがダウンロードされると、この回転イメージを削除します。

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {

[delegate showIndicator];

//Complex data downloading

[delegate hideIndicator];
}

したがって、これらのメソッドは connectionFinishedLoading が発生したときに呼び出されますが、呼び出されません。それらの実装は次のとおりです。

-(void)showIndicator;
{
    NSLog(@"Show indicator");
    UIImage *statusImage = [UIImage imageNamed:@"update.png"];
    activityImageView = [[UIImageView alloc] initWithImage:statusImage];
    // Make a little bit of the superView show through

    activityImageView.animationImages = [NSArray arrayWithObjects:
                                         [UIImage imageNamed:@"update.png"],
                                         [UIImage imageNamed:@"update2.png"],
                                         [UIImage imageNamed:@"update3.png"],
                                         [UIImage imageNamed:@"update4.png"],
                                         nil];
    activityImageView.frame=CGRectMake(13, 292, 43, 44);
    activityImageView.animationDuration = 1.0f;
    [rightView addSubview:activityImageView];
    [activityImageView startAnimating];
}
-(void)hideIndicator
{  NSLog(@"Hide indicator");
     [activityImageView removeFromSuperview];
}

ここで、connectionFinished イベントが呼び出される JManager オブジェクトを作成します。

-(IBAction)update:(id)sender
{
///la la la updating
JManager *manager1=[[JManager alloc] initWithDate:dateString andCategory:@"projects"];
            manager1.delegate=self;
            [manager1 requestProjects];
}

Jmanager オブジェクトの代わりにカスタム インジケーターを追加できないのはなぜですか? ありがとう!

4

1 に答える 1

1

メインスレッドから NSURLConnection を呼び出していると仮定すると、メソッドは非同期で実行されないため、開始から停止までの間にインジケーターを表示する機会がありません。

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {

    [delegate showIndicator];

    //Complex data downloading

    [delegate hideIndicator];
}

次のように、代わりにメソッドでを呼び出す必要があり[delegate showIndicator]ます。- (void)connectionDidReceiveResponse

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
    //connection starts
    [delegate showIndicator];
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {

    //connection ends
    [delegate hideIndicator];
}    
于 2012-02-03T10:40:05.463 に答える