Wait for an action to be done before loading a detailsView
in my app, I'm loading a detailsView
from a tableV开发者_StackOverflow中文版iew
. I need to get an XML document (with SOAP), parse it, and then display the informations I got in my detailsView
. So, when loading my detailsView
I want to wait for the parser to parse the entire document BEFORE displaying my detailsView
.
In my parser I'm using a NSURLConnection
, and methods of NSXMLParserDelegate
like parserDidStartDocument
, etc...
I've thought of using threads but I'm not getting anything conclusive.
I'm trying to be clear on what I want to do but it's pretty hard :s
I'll provide more infos if needed.
You can do it in either viewDidLoad or viewWillAppear Method but you have to make all your detailview's control hidden until it loads data from the server and then show it when you get response from the parser with the value you get in response. You can show loading indicator while you are parsing your response. You need to call your url Asynchronously.
Do something like this in your viewWillAppear Method :
NSURL *url = [NSURL URLWithString:@"www.yourwebserviceurlhere.com"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
Implement Connection delegate methods.
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data;
- (void)connectionDidFinishLoading:(NSURLConnection *)connection;
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error;
After you FinishLoadingData and you got response you need to parse your data by implementing XMLParser delegate method and when you finished parsing you need to show your detailview.
That's it. Hope this help.
精彩评论