Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4271140
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:24:06+00:00 2026-05-21T07:24:06+00:00

I’m really frustrated after spending like three hours googling around to solve this problem!!

  • 0

I’m really frustrated after spending like three hours googling around to solve this problem!! It’s probably an easy solution to it aswell.

I’m creating a really simple TableView app for the iPhone. It’s supposed to fetch an XML-document and parse it (already fixed) and then put the data into objects called HPobject!
One HPobject represents one day of data from the XML-file. Anyhow!

Then I want the object to be stored in a NSMutableArray so I can grab it later when I’m creating the table rows. But I can’t access it! My NSMutableArray is ALWAYS null! No matter what I do!

Here’s my code:

//THE .h FILE
#import "TBXML.h"
#import "HPobject.h"

@interface RootViewController : UITableViewController {
    NSMutableArray *listOfItems;
}

- (void)traverseElement:(TBXMLElement *)element;

//THE .m FILE
#import "RootViewController.h"
#import "HPobject.h"

@implementation RootViewController

- (void)viewDidLoad
{   
    NSMutableArray *listOfItems = [[NSMutableArray alloc] init];
    TBXML * tbxml = [[TBXML tbxmlWithURL:[NSURL URLWithString:@"http://www.hpprov.se/istasts.php?q=xxxxxxx"]] retain];

    if (tbxml.rootXMLElement)
        [self traverseElement:tbxml.rootXMLElement]; //Works fine!

    [tbxml release];
    [super viewDidLoad];
}

- (void) traverseElement:(TBXMLElement *)element {    
    do {
//Lots of parsing code which all works fine and gets me the variables up next!

            HPobject *currentObject = [[HPobject alloc] init];
            currentObject.antalRegistrerade = numRegistrerade;
            currentObject.inkomstBrutto = numBrutto;
            currentObject.inkomstNetto = numNetto;

            [listOfItems addObject:currentObject];

            NSLog(@"Array: %@", listOfItems); //RETURNS null!
            NSLog(@"Reg: %@, Net: %@, Brutt: %@", currentObject.antalRegistrerade, currentObject.inkomstNetto, currentObject.inkomstBrutto); //Returns the correct values!

            NSLog(@"%d stycken!", listOfItems.count); //Returns 0!! :(
            [currentObject release];

    } while ((element = element->nextSibling));  
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T07:24:07+00:00Added an answer on May 21, 2026 at 7:24 am

    You are defining listOfItems locally in viewDidLoad and then you try to access that in another method.

    Make sure you are using an instance variable defined in your interface definition (header).

    replace this line in viewDidLoad:

    NSMutableArray *listOfItems = [[NSMutableArray alloc] init];
    

    with

    listOfItems = [[NSMutableArray alloc] init];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.