好吧,所以我有點新的NSMutableArray類,我想我失去了一些明顯的東西。我有一個對象傳遞一個NSMutable陣列到我的窗控制器,像這樣在my.m:問題與NSMutableArray可見性/保留
summaryWindow = [[SummaryWindowController alloc] init];
[summaryWindow setGlobalStatusArray:globalStatusArray];
我在summaryWindow對象中的接收機的方法,以便:
-(void)setGlobalStatusArray:(NSMutableArray *)myArray
{
if ([myArray count] >0) {
if (globalStatusArray) {
[globalStatusArray release];
}
globalStatusArray = [[NSMutableArray alloc] initWithArray:myArray];
NSLog(@"Summary Window Init with new array: %@",globalStatusArray);
我看到的NSLog沒有問題,並在同一個對象(summaryWindow)我有以下方法:
- (NSMutableArray *)getGlobalStatusArray
{
return globalStatusArray;
}
現在我有globalStatusArray在我.h文件中聲明爲
NSMutableArray *globalStatusArray;
所以不應該這樣保留,因爲我使用:initWithArray?
當我嘗試在一個又一個IBAction爲方法訪問此值:
- (IBAction)refreshButtonClicked:(id)sender
{
NSLog(@"The user has clicked the update button");
[ aBuffer addObjectsFromArray: globalStatusArray];
NSLog(@"Buffer is currently:%@",aBuffer);
[tableView reloadData];
}
的NSMutable陣列爲null
2011-08-18 10:40:35.599 App Name[65677:1307] The user has clicked the update button
2011-08-18 10:40:35.600 App Name[65677:1307] Buffer is currently:(
)
我已經用我自己的方法來獲取值即嘗試[個體經營getGlobalStatusArray],但我錯過了一些巨大的東西。 FYI aBuffer在我的.h也宣稱,
而不是'nil',它看起來像你的數組是空的。如果它是'nil',它會記錄'(null)' – albertamg