NSthreading但仍未使用activityprogressview

时间:2010-06-24 06:30:51

标签: iphone objective-c

            [progressind startAnimating];

        [self performSelectorOnMainThread:@selector(methodgoeshere:) withObject:[NSDictionary dictionaryWithObjectsAndKeys: aURL, @"aURL", aURL2, @"aURL2", nil]
                            waitUntilDone:YES ];
        [progressind stopAnimating];

        [navigationController pushViewController:vFullscreen animated:YES];

在方法中,我有一个UIImageview,一旦下载就填充了图像,但问题是,activityprogress不能像我想的那样工作,它不会旋转。

1 个答案:

答案 0 :(得分:1)

您需要在新的后台线程中加载图像。 performSelectorOnMainThread调用 main 线程上的方法,而不是后台线程,这就是它阻塞的原因。

在后台线程中调用图像加载方法:

[progressind startAnimating];
[NSThread detachNewThreadSelector:@selector(methodgoeshere:) toTarget:self withObject:[NSDictionary dictionaryWithObjectsAndKeys: aURL, @"aURL", aURL2, @"aURL2", nil]];

然后在methodgoeshere中加载你的图像。一旦图像完成,加载然后你在主线程上调用一个方法让它知道你已经完成并停止活动进度指示器。

- (void) methodgoeshere:(...)... {
    // <Load your image here>

    // Then tell the main thread that you're done
    [self performSelectorOnMainThread:@selector(imageDoneLoading) withObject:nil waitUntilDone:YES ];        
}

- (void)imageDoneLoading {
    [progressind stopAnimating];
    // Do other stuff now that the image is loaded...
}