Reputation: 17665
i have declared 1 array in application delegate
@property(strong,nonatomic)NSMutableArray *books;
i have added objects to this array in 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;
}
i have declared this array in XMLParser.h like this
@interface XMLParser : NSObject {
NSMutableString *currentElementValue;
AppDelegate *appDelegate;
Book *aBook;
}
now i have to access this array in BooksDetailViewController.m , how do i access this array. in short how i can access array from application delegate into BooksDetailViewController
Upvotes: 0
Views: 171
Reputation: 15147
First of all you should have to alloc
and init
your array, then You can add objects in it.
You should have to create AppDelegate instance in your BooksDetailViewController
like this,
in .h file
AppDelegate *appDelegate;
and in .m file
appDelegate = [[UIApplication sharedApplication]delegate];
Now you can access your array like this,
appDelegate.books
Upvotes: 5