开发者

Problem in creating another thread

开发者 https://www.devze.com 2023-02-08 18:35 出处:网络
I am using NSThread to create new thread that displays images in my application. On the main thread I am working with a table view which is displaying data from XML file, in the same view I am display

I am using NSThread to create new thread that displays images in my application. On the main thread I am working with a table view which is displaying data from XML file, in the same view I am displaying images below. But, displaying images on new thread is not working properly.

- (void)viewDidLoad {
    [super viewDidLoad];
    [NSThread detachNewThreadSelector:@selector(startTheBackgroundJob) toTarget:self withObject:nil];
}

And the method in question:

- (void)startTheBackgroundJob {
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    currentLocationImageView = [[UIImageView alloc] init];
    NSArray *images = [NSArray arrayWithObjects:img1, img2, nil];
    [currentLoca开发者_JS百科tionImageView setAnimationImages:images];
    [currentLocationImageView setAnimationRepeatCount:0];
    [currentLocationImageView setAnimationDuration:5.0];

    [self.view addSubview:currentLocationImageView];
    [pool release];
}


now that you've started accepting the answers....

Without even looking at your code, the first thing to tell you is, you MUST perform UI activities on main thread... check this question for details...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号