views:

17

answers:

2

hi all,

im writing a news app, and im just planning it out in my head and need some help, before i start coding.

my app is a tab bar controller that is loading and displaying info from an xml feed. i am going to start the download of the xml within the app delegate in the background, so the app does not get closed down by the os, however this means that when my first table loads it will be blank , so i need a way of reloading the table once it has finished . i have encountered this issue before and couldnt work a way round it

last time i started the download of the info from the viewdidload method in the first view controller and tried a reloaddata , but that didn't seem to work. has anyone got a work around for this problem?

+1  A: 

[yourTable reloadData] is the way to go.

Make sure to call it on the main thread, and that your data structure is actually holding the correct data.

Eiko
managed to get it working thanks
richard Stephenson
A: 

ok, i chalked up some code but still having problems

in my app delegate i have ` [self performSelectorInBackground:@selector(loadAppContent) withObject:nil]; return YES; }

-(void)loadAppContent {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

// Do work . . .

// dismiss the holding view
Newcastle *newcastle = [[Newcastle alloc]init];
[newcastle loadNews];`

and then in my view controller i have

- (void)loadNews;{

// instantiate an array to hold the stories objects
stories = [[NSMutableArray alloc] init];



// Load and parse the stories.xml file

tbxml = [[TBXML tbxmlWithXMLFile:@"scores.xml"] retain];    

// Obtain root element
TBXMLElement * root = tbxml.rootXMLElement;

// if root element is valid
if (root) {

    // search for the first story element within the root element's children
    TBXMLElement *story = [TBXML childElementNamed:@"story" parentElement:root];

    while (story != nil) {

        //alloc and init story
        NewcastleStories *aStory = [[NewcastleStories alloc] init];



        //get the story headline and standfirst
        TBXMLElement *title = [TBXML childElementNamed:@"title" parentElement:story];
        aStory.headline = [TBXML textForElement:title];
        NSLog(@"headline : %@", aStory.headline);

        TBXMLElement *intro = [TBXML childElementNamed:@"intro" parentElement:story];
        aStory.standfirst = [TBXML textForElement:intro];

        //get image url

        TBXMLElement *pict = [TBXML childElementNamed:@"image" parentElement:story];
        aStory.picture = [TBXML textForElement:pict];


        // find the next sibling element named story
        story = [TBXML nextSiblingNamed:@"story" searchFromElement:story];


        //add to array an release
        [stories addObject:aStory];
        [aStory release];

    }


}

// release resources
[tbxml release];

[self dataLoaded];

} -(void) dataLoaded{ [self.newsStories reloadData]; }

still does not work , can anyone point out what i am doing wrong?

richard Stephenson