@interface Viewcontroller ()
{
Uiimageview* IV;
uibutton* btn;
Uilabel* LBL;
}
@end
@implementation Viewcontroller
-(void) Viewdidload {
[Super Viewdidload];
Iv=[[uiimageview alloc]initwithframe:cgrectmake (0, 0, 100, 100)];
Lbl=[[uilabel alloc]initwithframe:cgrectmake (0, 100, 100, 30)];
Btn=[[uibutton alloc]initwithframe:cgrectmake (0, 130, 100, 30)];
[Btn addtarget:self Action: @selector (LoadData) forcontrolevents:uicontroleventtouchupinside];
Btn.backgroundcolor=[uicolor Orangecolor];
[Self.view Addsubview:iv];
[Self.view ADDSUBVIEW:LBL];
[Self.view ADDSUBVIEW:BTN];
}
-(void) LoadData
{
Dispatch_async (Dispatch_get_global_queue (dispatch_queue_priority_high, 0), ^{
nsstring* [email protected] "http://f4.topitme.com/4/e4/5e/1132253263b8b5ee44o.jpg";
nsdata* data=[[nsdata Alloc]initwithcontentsofurl:[nsurl Urlwithstring:url];
uiimage* Image=[[uiimage Alloc]initwithdata:data];
if (image) {
Dispatch_async (Dispatch_get_main_queue (), ^{
self->iv.image=image;
});
}
Else
{
NSLog (@ "Download error");
}
});
Dispatch_async (Dispatch_get_global_queue (dispatch_queue_priority_high, 0), ^{
nsstring* [email protected] "123";
if (str) {
Dispatch_async (Dispatch_get_main_queue (), ^{
self->lbl.text=str;
});
}
Else
{
NSLog (@ "Download error");
}
});
}
GCD large central Distribution simple application Example