在delegate中声明了一个数组:
@property(strong,nonatomic)NSMutableArray *books;
然后在XMLParser.m中给这个数组添加对象:
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if([elementName isEqualToString:@"Books"])
return;
NSLog(@"i m in didEndElement");
if([elementName isEqualToString:@"Book"]) {
[appDelegate.books addObject:aBook]; //here i have added objects to array
[aBook release];
aBook = nil;
NSLog(@"books=%@",appDelegate.books);
}
else
[aBook setValue:currentElementValue forKey:elementName];
[currentElementValue release];
currentElementValue = nil;
}
在XMLParser.h中声明数组:
@interface XMLParser : NSObject {
NSMutableString *currentElementValue;
AppDelegate *appDelegate;
Book *aBook;
}
现在需要访问在BooksDetailViewController.m中的数组,怎么实现?如何从应用delegate中访问数组?