I download certain data, and when it’s downloaded this method is called:
- (void)connectionDidFinishLoading:(NSURLConnection *)connection;
In this method I should present a rotating image in the view controller which I do with delegateing and when the data is downloaded I remove this roatating image:
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[delegate showIndicator];
//Complex data downloading
[delegate hideIndicator];
}
So those method are called when the connectionFinishedLoading happen, but they are not called. Here are their implementations:
-(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];
}
And that’s where I create JManager object for which connectionFinished event is called:
-(IBAction)update:(id)sender
{
///la la la updating
JManager *manager1=[[JManager alloc] initWithDate:dateString andCategory:@"projects"];
manager1.delegate=self;
[manager1 requestProjects];
}
Why can’t my custom indicator adding can’t be done on the behalf of Jmanager object? thanks!
Assuming you are calling your NSURLConnection from the main thread, the method is not executed asynchronously, so the indicator has no opportunity to be displayed between you starting and stopping it.
You should call the
[delegate showIndicator]in your- (void)connectionDidReceiveResponsemethod instead, like this: