0
我有一個圖像類,我想根據圖像存儲一些信息:類變量值迷路
@interface GEOImage : UIImage
{
NSString *title;
NSString *imgDescription;
NSString *latitude;
NSString *longitude;
NSDictionary *info;
NSURL *urlToImage;
}
@property (nonatomic, retain) NSString *title, *imgDescription, *latitude, *longitude;
@property (nonatomic, retain) NSDictionary *info;
@property (nonatomic, retain) NSURL *urlToImage;
@end
在TabBarController
第一片我例如設置:
self.chosenImage.title = @"Roflmao"
而在另一個第二個選項卡我把它打印出來:
NSLog("Title:%@", self.chosenImage.title);
但在第二個選項卡標題爲"null"
。 如果我檢查chosenImage
的對象引用,它們是相同的,如果我在設置它後在第一個標籤中打印標題,則一切正常。不知何故,當我更改標籤時,類變量會丟失(或被ARC移動到垃圾桶?)。
我在聲明中的屬性做錯了什麼?或者在設置類變量時還有其他一些錯誤?
挑剔:你的標題,imgDescription,緯度等都是「實例變量」 - 從「類變量」斷然不同。其次,你如何檢查在兩種情況下選擇的圖像是否相同? – hooleyhoop
如果這是在兩個單獨的選項卡,大概是在兩個單獨的視圖控制器 - 他們都不會有自己的self.chosenImage?你是否記錄過,是self.chosenImage零? – jrturton
如果您使用ARC(如您的問題中所述),則應聲明屬性爲「強」而不是「保留」。 – tarmes