Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The solution to your problem lies in delegation (As the word suggests you will be appointing some one else to take action when a situation presents itself.)</p> <p>You have already used this in the following piece of your code.</p> <pre><code>NSURLRequest *request = [NSURLRequest requestWithURL:data_url]; connection = [NSURLConnection connectionWithRequest:request delegate:self]; </code></pre> <p>Here when you have set self as the delegate for your NSURLConnection you are telling the compiler to send you any appropriate messages related to the connection. These messages include didReceiveResponse,didReceiveData,connectionDidFinishLoading. </p> <p>So let's implement these methods in your class and they will look something like this.</p> <p>KDJSONParser.m</p> <pre><code>- (NSMutableArray *)fetchData { [UIApplication sharedApplication].networkActivityIndicatorVisible = YES; NSURLRequest *request = [NSURLRequest requestWithURL:data_url]; connection = [NSURLConnection connectionWithRequest:request delegate:self]; if(connection) { webdata = [[NSMutableData alloc]init]; } } - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { // This method is called when the server has determined that it // has enough information to create the NSURLResponse. // It can be called multiple times, for example in the case of a // redirect, so each time we reset the data. // receivedData is an instance variable declared elsewhere. [webdata setLength:0]; } - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { // Append the new data to receivedData. // receivedData is an instance variable declared elsewhere. [webdata appendData:data]; } - (void)connectionDidFinishLoading:(NSURLConnection *)connection { [connection release]; //Parse the webdata here. Your array must be filled now. [self parseTheJSONData]; } -(void)parseTheJSONData { //Do your parsing here and fill it into data_array [self.delegate parsedArray:data_array]; } </code></pre> <p>And in your other class add this line in you refresh method</p> <pre><code>block_stats.delegate = self; </code></pre> <p>and implement </p> <pre><code>-(void)parsedArray:(NSMutableArray *)data_array; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload