我有一個for循環設置按鈕上的背景圖片,基本上按鈕是不同的項目&不能靜態設置的縮略圖預覽,但因爲它貫穿所有的代碼給出了一個警告UIViews,但然後調用setBackgroundImage不適用於所有視圖。警告是一種刺激,我明白它在抱怨什麼,我該如何擺脫它? (我不想關閉警告,我想解決這個問題)警告設定代碼
// For loop to set button images
for (UIView *subview in [self.view subviews]) // Loop through all subviews
{
// Look for the tagged buttons, only the 8 tagged buttons & within array bounds
if((subview.tag >= 1) && (subview.tag <= 8) && (subview.tag < totalBundles))
{
// Retrieve item in array at position matching button tag (array is 0 indexed)
NSDictionary *bundlesDataItem = [bundlesDataSource objectAtIndex:(subview.tag - 1)];
// Set button background to thumbnail of current bundle
NSString *picAddress = [NSString stringWithFormat:@"http://some.thing.com/data/images/%@/%@", [bundlesDataItem objectForKey:@"Nr"], [bundlesDataItem objectForKey:@"Thumb"]];
NSURL *picURL = [NSURL URLWithString:picAddress];
NSData *picData = [NSData dataWithContentsOfURL:picURL];
// Warning is generated here
[subview setBackgroundImage:[UIImage imageWithData:picData] forState:UIControlStateNormal];
}
}
真棒,這工作就像一個魅力,謝謝麥克,你是一個傳奇。 – 2010-04-23 13:48:32