2014-09-24 26 views
-1

Im在iOS開發中的新功能,以及即時通訊嘗試獲取在xcode中工作的應用程序。在我的應用程序中,我有很多imageview的基本上應該做同樣的。首先,我開始寫IBOutlet給他們所有人;當在IBOutletCollection中使用而不是IBOutlet時,UIImageViews有所不同

IBOutlet UIImageView image1; 
IBOutlet UIImageView image2; 
IBOutlet UIImageView image3; 
... 

但是這將是我一個更好的解決方案,創建一個IBOutletCollection和連接到情節提要每個UIImageView的。所以我創建了一個IBOUtletCollection;

IBOutletCollection(UIImageView) NSArray *images; 

但是後來,我開始在代碼中得到錯誤,以前的代碼使用簡單的IBOutlets;

imageToZoom.image = images.image; - "Image" property not found in Array object. 

和警告,如下列:

[images setUserInteractionEnabled:YES]; - NSArray may not respond 'setUserInteractionEnabled' 
[images addGestureRecognizer:tapOnce]; - NSArray may not respont 'addGestureRecognizer' 

我明白了,這不是一個的UIImageView了,它是一個數組,但我不知道如何解決這些錯誤。例如,我如何引用數組中的項目的「圖像」屬性。在UIImageView中不是簡單的「ImageView.image」,但它現在不工作。

預先感謝!

回答

0

是的,圖片是實物類的NSArray的,這個數組中的對象是UIImageView的,所以你可以做到這一點

for (int i=0, i< images.count,i++) { 
UIImageView *imageView = (UIImageView *)images[i]; 
imageView.image = images.image; 
[imageView setUserInterfaceEnable:YES]; 
[imageView setGestureRecognizer:tapOnce]; 
} 
相關問題