Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To give a more detailed example:</p> <p>in your .h file do</p> <pre><code>@interface YourClass : YourSuperclass&lt;NSURLConnectionDataDelegate&gt; </code></pre> <p>in your .m file do</p> <pre><code>@property (nonatomic) NSMutableData *imageData; @property (nonatomic) NSUInteger totalBytes; @property (nonatomic) NSUInteger receivedBytes; </code></pre> <p>And somewhere call</p> <pre><code>NSURL *url = [NSURL URLWithString:@"http://i0.kym-cdn.com/entries/icons/original/000/005/545/OpoQQ.jpg?1302279173"]; NSURLRequest *request = [NSURLRequest requestWithURL:url]; NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES]; </code></pre> <p>And also implement the delegate methods</p> <pre><code>- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) urlResponse; NSDictionary *dict = httpResponse.allHeaderFields; NSString *lengthString = [dict valueForKey:@"Content-Length"]; NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init]; NSNumber *length = [formatter numberFromString:lengthString]; self.totalBytes = length.unsignedIntegerValue; self.imageData = [[NSMutableData alloc] initWithCapacity:self.totalBytes]; } - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { [self.imageData appendData:data]; self.receivedBytes += data.length; // Actual progress is self.receivedBytes / self.totalBytes } - (void)connectionDidFinishLoading:(NSURLConnection *)connection { imageView.image = [UIImage imageWithData:self.imageData]; } - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { //handle error } </code></pre>
    singulars
    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