Amazon.com Widgets Getting Data from a web service and showing on screen when got the data
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 25, 2013, 09:39:41 PM
Home Help Search chat Login Register   
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+  Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+  iOS Programming
| |-+  General Questions
| | |-+  Getting Data from a web service and showing on screen when got the data
Pages: [1]   Go Down
Print
Author Topic: Getting Data from a web service and showing on screen when got the data  (Read 689 times)
Steve Shanks
Newbie
*
Posts: 16






« on: June 29, 2012, 02:26:06 PM »

Hi
I have  an app where i'm reading xml data from a web service.

I'm happy that I can connect to the service and read the data using NSURLRequest requestWithURL: which I believe works async and I eventually get the data back ok.

However, I'm unsure on the best way to handle the UI while this is happing as the code will keep executing.
Basically I want to show the view that will display the data while getting the data from a web service (I have a seperate object that I instantiate and then make the calls to handle the web service)

How do I notify the calling routine when the web service has finished getting the data with the call '- (void) connectionDidFinishLoading:(NSURLConnection *)connection' so that I can then parse the returned xml and show it on the screen?

I'm thinking about looking into custom delegates?

Any pointers much appreciated Smiley

Thanks
Steve
« Last Edit: June 29, 2012, 03:18:39 PM by Steve Shanks » Logged
jonthornham
Full Member
***
Posts: 169



WWW Email




« Reply #1 on: July 03, 2012, 11:30:52 AM »

I am currently working on a very similar problem.  You've asked some great questions.

In my application I have made the call to a separate parser method in the -(void) connectionDidFinishLoading:(NSURLConnection *)connection

Code: (Objective-C)
myQueue = dispatch_queue_create("com.flocycling.gcdparser", NULL);
        dispatch_async(myQueue, ^ { [self parseRSSData: RSSFeedData];
                                    [self.myTableView reloadData]; } );

RSSFeedData is just the NSMutableData object I used to gather the XML data pulled down from the website.  I am also using a separate thread so that the interface stays interactive.  Once the data is parsed I call reloadData on my table view. I am listing each article of the XML feed in a tableView and then when it is selected I open the article in a  webview. 

Here is my parser method that gets called.

Code: (Objective-C)
-(void) parseRSSData: (NSData *) rssData
{
    NSXMLParser *parser = [[NSXMLParser alloc] initWithData: rssData];
    [parser setDelegate: self];
    [parser parse];
}

For the separate thread I notified Grand Central Dispatch right after the @implementation call.

Code: (Objective-C)
dispatch_queue_t myQueue;

I did all of this in the viewController that owns the tableView.  I don't feel there is a need to have delegates etc for this functionality.  I could be wrong but it's the way I worked it out.

I hope this was somewhat helpful.  Let me know if I can help clarify anything. 

Take care,

Jon
Logged

Jon Thornham
Steve Shanks
Newbie
*
Posts: 16






« Reply #2 on: July 11, 2012, 06:52:42 AM »

Thanks for the reply Jon...only just taken a look as been away on holiday for a week with a ban on the MacBook Pro coming along Cheesy

I'll take a closer look at this as never used these calls before

Cheers
Steve
Logged
Pages: [1]   Go Up
Print
Jump to:  



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.