只是被奇怪的东西卡住了。我有以下代码:

-(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];
}


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

提前致谢

最佳答案

由于您的方法被声明为

-(void)updateImageButton


相应的选择器为@selector(updateImageButton),不带冒号。更改:

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




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


它应该工作。

关于objective-c - performSelectorOnMainThread奇怪,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6056420/

10-09 05:13