-(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