AntonMac
AntonMac

Reputation: 353

Getting an array from another class objective-C

I have xml file and I raed all information in xml file and store in array,

here is my starDidElement file for storing in array:

-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI 
 qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{

if ([elementName isEqualToString:@"Presentation"]) {
    NSLog(@"user element found – create a new instance of User class...");
    app.presentationArray = [[NSMutableArray alloc] init];
    thePresentation = [[Presentation alloc] init];
    thePresentation.pLabel = [attributeDict objectForKey:@"label"];
    NSLog(@"PLabel: %@", thePresentation.pLabel);

}else if ([elementName isEqualToString:@"slides"]) {
    NSLog(@"Slides");

    thePresentation.slides = [NSMutableArray array];

and in my header I have

   Presentation thePresentation;

would you please help me to inpelement this

Thanks In advance

Edit:

Presentation *aPresentation = [app.presentationArray objectAtIndex:0];
NSLog(@"Presentation is: %@ and it's Slide Count is: %d",aPresentation.pLabel, aPresentation.slides.count);

Slide *aSlide = [aPresentation.slides objectAtIndex:0];
NSLog(@"Slide Label is: %@", aSlide.sLabel);

UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setTitle:[NSString stringWithString:aSlide.sLabel] forState:UIControlStateNormal];
btn.frame = rect;
[btn setTag:i];
[btn addTarget:self action:@selector(buttonClick:)  forControlEvents:UIControlEventTouchUpInside];
[imageView addSubview:btn];

then The log is

[788:c07] Presentation is: (null) and it's Slide Count is: 0 [788:c07] Slide Label is: (null)

Upvotes: 0

Views: 442

Answers (2)

user1082071
user1082071

Reputation:

What happens when you do it this way:

Presentation *aPresentation = [app.presentationArray objectAtIndex:0];
NSLog(@"Presentation is: %@ and it's Slide Count is: %d",aPresentation.pLabel, aPresentation.slides.count);

Slide *aSlide = [aPresentation.slides objectAtIndex:0];
    NSLog(@"Slide Label is: %@", aSlide.sLabel);

    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setTitle:[NSString stringWithString:aSlide.sLabel] forState:UIControlStateNormal];
    btn.frame = rect;
    [btn setTag:i];
    [btn addTarget:self action:@selector(buttonClick:)  forControlEvents:UIControlEventTouchUpInside];
    [imageView addSubview:btn];

Upvotes: 2

vishy
vishy

Reputation: 3231

Add a public method in your viewController, once your xml parsing is done call that public method it means, you are telling your viewController data is ready & update UI.

You can use appDelegate to inform viewController that data is ready, as appDelegate will be having instance of your viewController.

EDIT: You can have the following:

//in viewController.h
- (void) viewFillUp;

//in viewController.m
-(void)viewFillUp
{
      Slide *aSlide = [thePresentation.slides objectAtIndex:0];
      NSLog(@"Slide Label is: %@", aSlide.sLabel);

      UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
      [btn setTitle:[NSString stringWithString:aSlide.sLabel] forState:UIControlStateNormal];
      btn.frame = rect;
      [btn setTag:i];
      [btn addTarget:self action:@selector(buttonClick:)  forControlEvents:UIControlEventTouchUpInside];
      [imageView addSubview:btn];
}

//in appDelegate.h
 - (void) parsingDone;

//in appDelegate.m
- (void) parsingDone
{
    //suppose ur viewController instance is self.viewController
    [self.viewController viewFillUp]
}

Upvotes: 0

Related Questions