@implementaion Fkviewcontroller
-(void) viewdidload
{
[Super Viewdidload];
}
-(Ibaction) ShowImage: (ID) sender
{
nsstring* url = @ "http://www.crazyit.ortg/logo.jpg";
Create a new Thread object
Nsthread *thread = [Nsthread alloc] initwithtarget:self selector: @selector [downloadimagefromurl:) Object:url];
Start thread
[Thread start];
}
Defines a method as the thread execution body
-(void) Downloadimagefromurl: (NSString *) URL
{
Getting data from the network
NSData *data = [[NSData alloc] Initwithcontentofurl:[nsurl Urlwithstring:url]];
UIImage *image = [[UIImage alloc] initwithdata:data];
if (image = nil)
{
Execute UpdateUI in the main thread: method
[Self Performselectoronmainthread: @selector (updateUI:) withobject:image Waituntildone:yes];
}
Else
{
NSLog (@ "------Download Image Error---");
}
}
-(void) UpdateUI: (uiimage*) image
{
Self.iv.image = image;
}
Use threads to download network pictures