performSelectorOnMainThread陌生感

Adv*_*010 0 multithreading objective-c ios4 ios

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

-(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];
}
Run Code Online (Sandbox Code Playgroud)

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

提前致谢

小智 8

由于您的方法被声明为

-(void)updateImageButton
Run Code Online (Sandbox Code Playgroud)

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

[self performSelectorOnMainThread:@selector(updateImageButton:) 
                       withObject:nil 
                    waitUntilDone:YES];
Run Code Online (Sandbox Code Playgroud)

[self performSelectorOnMainThread:@selector(updateImageButton) 
                       withObject:nil 
                    waitUntilDone:YES];
Run Code Online (Sandbox Code Playgroud)

它应该工作.