0

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)

2
  • You do it essentially the same way you'd do it in Java. Commented Oct 15, 2012 at 15:30
  • @HotLicks can you write your code in answer part please Commented Oct 15, 2012 at 15:53

2 Answers 2

2

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];
Sign up to request clarification or add additional context in comments.

7 Comments

first I had error with undeclared identifier app, that I added AppDelegate app; in my header file but , i have error Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '** -[NSPlaceholderString initWithString:]: nil argument'
[788:c07] Presentation is: (null) and it's Slide Count is: 0 [788:c07] Slide Label is: (null)
That means there is nothing in your app.presentationArray. There are no Presentations added to it.
:((( I really tierde do you know what would be problem, please help me
Come to iPhone/iPad room and let's continue discussion there.
|
0

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]
}

8 Comments

but I allreday have Presentation thePresentation; , would you please write the code you mean
where is ur startDidElement code written..? i mean in which class or viewController
would you please add it in your answer I need the code I'm new to objective-c
but you didn"t change my code, is the same, my problem is I don't know how should I add value to my object
what should I right instead of this Slide *aSlide = [thePresentation.slides objectAtIndex:0]; or addinn to this
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.