在應用程序委託中,我爲多個視圖控制器創建了一個數組以供引用。但是,當我嘗試在一個視圖中更新數組時,它在另一個視圖中變爲空。更新appDelegate中的變量
視圖1:
MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
dataTempForSearch = appDelegate.myData;
我然後有一個XML解析器,插入一個對象到陣列。
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
if ([elementName isEqualToString:@"CompanyName"]) {
// save values to an item, then store that item into the array...
[item setObject:currentTitle forKey:@"title"];
[item setObject:currentAddress forKey:@"address"];
[item setObject:currentCity forKey:@"city"];
[item setObject:currentCountry forKey:@"country"];
[dataTempForSearch addObject:[item copy]];
}
}
這將返回一切在圖1細,但鑑於2 I具有:
- (void)viewDidLoad {
MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
dataTempForMap = appDelegate.myData;
NSLog(@"myData appDelegate from: %@", dataTempForMap);
}
當該第二視圖被加載,dataTempForMap
返回一個空數組。
我想你可能需要顯示myData的初始化位置和屬性設置的任何地方。 – 2009-11-09 16:55:58