[英]UIImage not displayed
我正在使用iOS 7 SDK和Xcode5。我想在UITabBarItem上設置圖標。 我正在使用以下方法。
setFinishedSelectedImage: withFinishedUnselectedImage:
一直到現在。 但是突然它停止顯示圖像。
我嘗試了以下各種選擇:
[img imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
[tabBarItem setSelectedImage:img];
[tabBarItem setImage:img];
[[UITabBarItem alloc] initWithTitle:title image:img selectedImage:img];
他們都沒有工作。 在這里, img
是從URL下載的圖像。
然后,我嘗試使用應用程序資源中的圖像之一進行顯示。
之后,我嘗試使用背景顏色為紅色的臨時UIImageView
並將img
設置為此UIImageView
,它顯示為紅色而不是img
。
但奇怪的是,我在其他顯示正確顯示的視圖控制器中使用了相同的img
。
任何想法如何解決這個問題?
這是我在代碼中的錯誤。 我必須在聲明時將img
初始化為一些UIImage
。 下面顯示了問題所在。
UIImage * img; // Image not initialized
// This condition was not satisfied and hence `img` was not storing any time.
if (condition)
{
img = ...;
}
// Below condition should have been satisfied if `img` was not initialized.
// But it did not. I am not getting why.
if (!img)
{
NSLog(@"Image is nil");
}
[tabBarItem setImage:img];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.