I have this simple scenario:
- main.m (which is my main class)
- myClass.m (which is an additional class)
In my plans it should happen something like this
(in MAIN.m)
myClass *foo = [[myClass alloc] init];
NSArray *array = [foo returnAnArray];
What myClass does is opening a new NSURLConnection, retrieving some data and - when it's ready - parsing it and returning an array.
To return an array with the parsed data I wrote this simple
(NSArray *) returnArray:(NSString *)dataDownloadedFro开发者_如何学编程mWeb
In order to know when the data has ACTUALLY finished downloading and when to start parsing it, I'm using
- (void) connectionDidFinishDownloading: (NSURLConnection *connection)
But WHERE and HOW can I call returnArray: if connectionDidFinishLoading is VOID? :(
I hope this makes sense... I'm really stuck and I cannot seem to find a solution. I tried with NSNotification but it didn't seem to work either.
Thanks everybody for the support! Enrico
Presumably you mean
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
?
Anyway, you dont wait until it has finished - you parse the data when it is ready in
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
- connectionDidFinishLoading: is letting you know that there wont be anymore data coming your way.
You need to implement connectionDidFinishDownloading yourself. You need to create a delegate object that you pass to NSURLConnection when you create it. The delegate object needs to implement connectionDidFinishDownloading.
The NSURLConnection will then call connectionDidFinishDownloading on your delegate object at the approperiate time.
There's further info here
精彩评论