2011-05-19 29 views
0

只是卡住了奇怪的事情。我有以下代碼:performSelectorOnMainThread奇怪

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

它崩潰,發生了無法識別的選擇器發送實例錯誤。上面的代碼有什麼問題?

預先感謝

回答

8

由於被宣佈你的方法

-(void)updateImageButton 

相應選擇器是@selector(updateImageButton)末尾沒有結腸。更改:

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

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

,它應該工作。

+0

感謝它做了伎倆..但按鈕的背景圖像仍然沒有更新,雖然圖像被創建,真的存在於文件系統中...什麼是做錯了? – Adviser2010 2011-05-19 09:48:04

+0

@ Adviser2010:您正在爲UIControlEventTouchUpInside設置背景圖像,即在按鈕內釋放觸摸時。那是你想要的嗎?你可以做一個快速的NSLog(@「%@」,img)來確認這個東西已經加載,而且你也不應該因爲沒有擁有引用而釋放它。 – Tommy 2011-05-19 11:30:30

+0

不,我想到我使用了錯誤的UIControlEvent ...在應用了正確的一個之後 - 它的功能就像魅力 – Adviser2010 2011-05-31 05:04:53