performSelectorOnMainThread陌生感

时间:2011-05-19 09:20:13

标签: objective-c multithreading ios ios4

只是坚持着奇怪的事情。我有以下代码:

-(void)ImageDownloadCompleat
{
    [self performSelectorOnMainThread:@selector(updateImageButton:) 
                           withObject:nil 
                        waitUntilDone:YES];
}

-(void)updateImageButton {
    NSLog(@"image OKEY");
    UIImage *img = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:
                                                     @"%@/%@.jpg",pathPreview,self.idProducts]];
    //images.image = img;

    [images setBackgroundImage:img forState:UIControlEventTouchUpInside];
    [img release];
}

它与发送到实例错误的无法识别的选择器崩溃。上面的代码有什么问题?

提前致谢

1 个答案:

答案 0 :(得分:8)

由于您的方法被声明为

-(void)updateImageButton

相应的选择器是@selector(updateImageButton) ,没有尾随冒号。更改:

[self performSelectorOnMainThread:@selector(updateImageButton:) 
                       withObject:nil 
                    waitUntilDone:YES];

[self performSelectorOnMainThread:@selector(updateImageButton) 
                       withObject:nil 
                    waitUntilDone:YES];

它应该有用。