2011-01-05 46 views
0

快速簡單的問題。我有一個UIButtons的滾動視圖,當你按下它們時,這些翻轉過來。一個按鈕必須顯示一個productImage。由於這些圖像來自web服務,我必須使用AsyncImageView加載它們。唯一的問題是,當我將AsyncImageView添加爲按鈕的子視圖時,無法再按下該按鈕。UIButton上的AsyncImageView

如何按下AsyncImageView?在按鈕後面添加AsyncImageView當然不是一個選項。

for (int i = 1; i < [searchResults2 count]; i++) { 
    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(((10*i) + ((i - 1)*90)), 40, 90, 90)];   
    [button setBackgroundColor:[UIColor whiteColor]]; 
    [button setAlpha:0.9]; 

    CGRect frame; 
    frame.size.width=90; 
    frame.size.height=90; 
    frame.origin.x=0; 
    frame.origin.y=0; 
    AsyncImageView* asyncImage = [[[AsyncImageView alloc] initWithFrame:frame] autorelease]; 
    asyncImage.tag = 999; 
    [asyncImage loadImageFromURL:[NSURL URLWithString:[[searchResults2 objectAtIndex:(i-1)] 
                 searchObjectImageUrl]]]; 
    [button addSubview:asyncImage.view]; 
    button.tag = i; 
    [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];  
    [scrollView addSubview:button]; 
} 

在此先感謝。

編輯:解決未使用AsyncImageview和寫一個簡單的圖像下載。

+0

爲什麼不能ü設置按鈕的圖像popertyü一次取回您的異步形象? – Daniel 2011-01-05 15:26:23

+0

當我嘗試訪問圖像屬性時,AsyncImageView的子視圖仍然爲空。所以圖像還不能訪問。 – Lewion 2011-01-05 15:35:39

回答

2

試試這個:

asyncImage.userInteractionEnabled = NO; 

這應當引起任何觸摸事件「砸」了asyncImage通過在已userInteractionEnabled設置爲YES z順序的下一個對象。

-S

+0

我最終爲圖片寫了一個下載器。我確實認爲我檢查了那一個。但還是謝謝:) – Lewion 2011-01-11 12:07:29

+0

這是行不通的。如果沒有,你也可以嘗試asyncImage.exclusiveTouch = NO; (但我不需要這最後一部分)。 - http://uihacker.blogspot.com/2010/04/iphone-subviews-in-uibuttons-block.html – RyanJM 2011-02-14 22:04:05

0

您可以使用下面的事情

asyncImage.userInteractionEnabled = NO; 
asyncImage.exclusiveTouch = NO;