iPhone下载指示器不显示
我下载某些数据,当它被下载时,这个方法被调用:
- (void)connectionDidFinishLoading:(NSURLConnection *)connection;
在这个方法中,我应该在视图控制器中呈现一个旋转图像,我用委托来做,当下载数据时,我删除这个旋转图像:
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[delegate showIndicator];
//Complex data downloading
[delegate hideIndicator];
}
所以这些方法被调用时连接完成加载发生,但它们没有被调用。以下是它们的实现:
-(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];
}
这就是我创建 JManager 对象并为其调用 connectionFinished 事件的地方:
-(IBAction)update:(id)sender
{
///la la la updating
JManager *manager1=[[JManager alloc] initWithDate:dateString andCategory:@"projects"];
manager1.delegate=self;
[manager1 requestProjects];
}
为什么我的自定义指标添加不能代表 Jmanager 对象完成?谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您从主线程调用 NSURLConnection,该方法不是异步执行的,因此指示器没有机会在您启动和停止之间显示。
您应该在
- (void)connectionDidReceiveResponse
方法中调用[delegate showIndicator]
,如下所示: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)connectionDidReceiveResponse
method instead, like this: