2010-06-17 23 views
0

嘿傢伙。我有兩個類,SelectionScreenTable & GraphView。在類之間傳遞數組,不見了?

在SelectionScreenTable類.H,我宣佈一個NSMutableArray的叫usagedatas

NSMutableArray *usagedatas; 

} 
@property (nonatomic, retain) NSMutableArray *usagedatas; 

在SelectionScreenTable class.m我記得@synthesize。 後來,在處理我的方法,我做了

NSLog(@"usagedatas count:%i",usagedatas.count); 

,以檢查它是否具有價值,它返回1.所以是其良好了這一點。

而在 - (void)dealloc中,我記得要釋放它。

[usagedatas release]; 

因此,現在來試圖在另一個類中使用它。

在GraphView.m中,我導入了「SelectionScreenTable.h」。 在 - (無效)viewDidLoad中,我沒有

SelectionScreenTable *UD = [SelectionScreenTable alloc]; 

NSLog(@"GraphView UD.usagedataas.count = :%i",UD.usagedatas.count); 

它返回0。

任何想法的傢伙?

+0

忘了提及我試過 SelectionScreenTable * UD = [[SelectionScreenTable alloc] init]; 不能工作 – Kenneth 2010-06-17 09:55:25

+0

在你顯示的代碼上,你只是創建一個屬性作爲指向數組的指針。你真的把這個屬性設置爲某個東西嗎?否則,它將是'nil','count'消息將返回0。 – pgb 2010-06-17 22:21:21

回答

0

嘿傢伙,我解決了它,而不是在AppDelegate中創建數組。然後在SelectionScreenTable中,我從AppDelegate獲取數組並對其進行編輯。 然後在GraphView中,我只是從AppDelegate調用數組,並返回一個值。