Get asynchronous request Picture step

Source: Internet
Author: User

-(Ibaction) GetImage: (ID) Sender {

1, prepare the URL

NSString *str = @ "http://e.hiphotos.baidu.com/image/h%3D1200%3Bcrop%3D0%2C0%2C1920%2C1200/sign= E13d66699825bc31345d059a6eefb6d2/6159252dd42a2834f85385ac5ab5c9ea14cebfa4.jpg ";

Nsurl *url = [Nsurl urlwithstring:str];

2, create the Request object

Nsurlrequest *request = [Nsurlrequest Requestwithurl:url];

Linked objects, block async

__block Mxtviewcontroller *weakself = self;

Nsoperationqueue *queue = [[Nsoperationqueue new] autorelease];

[Nsurlconnection sendasynchronousrequest:request queue:queue completionhandler:^ (NSURLResponse *response, NSData * Data, Nserror *connectionerror) {

Get Data

UIImage *image = [UIImage imagewithdata:data];

Back to the main thread update page

Dispatch_sync (Dispatch_get_main_queue (), ^{

Block can not access the property using _imageview, it will cause self reference count +1, cannot use strong reference

To use weak

WeakSelf.imageView.image = image;

});

}];

Get asynchronous request picture step

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.