First, create a corresponding spatial view, such as:
Second, write the corresponding. h code, as follows:
#import <UIKit/UIKit.h> @interface viewcontroller:uiviewcontroller@property (weak, nonatomic) Iboutlet Uiactivityindicatorview *activwaitnetwork; @property (weak, nonatomic) Iboutlet Uiprogressview *pgrsdownload;@ Property (weak,nonatomic) Nstimer *timer;-(ibaction) Onclickstartrequest: (ID) sender;-(ibaction) Onclickdownload: (ID ) Sender; @end
Third, write the implementation of the corresponding. m file, and comment more detailed:
#import "ViewController.h" @interface Viewcontroller () @end @implementation viewcontroller@synthesize activwaitnetwork; @synthesize pgrsdownload; @synthesize timer;-(void) viewdidload{[super viewdidload];//do any additio NAL Setup after loading the view, typically from a nib.} -(Ibaction) Onclickstartrequest: (ID) sender{//If it is running, stop or start running load if ([Activwaitnetwork isanimating]) {[ Activwaitnetwork stopanimating]; }else{[Activwaitnetwork startanimating]; }}-(ibaction) Onclickdownload: (ID) sender{//Restart Progress pgrsdownload.progress = 0; Timing task with new Progerss Progress timer = [Nstimer scheduledtimerwithtimeinterval:1.0 target:self selector: @selector (update) Useri Nfo:nil Repeats:yes]; }-(void) update{pgrsdownload.progress = pgrsdownload.progress + 0.1; When progress is complete, prompt to download complete if (pgrsdownload.progress = = 1) {[Timer invalidate]; Uialertview *alert = [[Uialertview alloc] initwithtitle:@ "Warm tip" message:@ "File Download Complete" Delegate:selfcancelbuttontitle:@ "OK" otherbuttontitles:@ "Cancel", nil]; [Alert show]; }}-(void) didreceivememorywarning{[Super didreceivememorywarning]; Dispose of any resources the can be recreated.} @end
Four, the operation effect, as follows:
Code Address: http://download.csdn.net/detail/jiangtao_st/7684965