iPhone下载指示器不显示

发布于 2025-01-02 02:44:44 字数 1736 浏览 3 评论 0原文

我下载某些数据,当它被下载时,这个方法被调用:

- (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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

还给你自由 2025-01-09 02:44:44

假设您从主线程调用 NSURLConnection,该方法不是异步执行的,因此指示器没有机会在您启动和停止之间显示。

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

    [delegate showIndicator];

    //Complex data downloading

    [delegate hideIndicator];
}

您应该在 - (void)connectionDidReceiveResponse 方法中调用 [delegate showIndicator],如下所示:

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

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

    //connection ends
    [delegate hideIndicator];
}    

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.

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

    [delegate showIndicator];

    //Complex data downloading

    [delegate hideIndicator];
}

You should call the [delegate showIndicator] in your - (void)connectionDidReceiveResponse method instead, like this:

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

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

    //connection ends
    [delegate hideIndicator];
}    
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文