iOS Sixth day (2:10 seconds Countdown)

Source: Internet
Author: User

10 Seconds Countdown

#import "HMViewController.h"@interfaceHmviewcontroller () <UIAlertViewDelegate>@property (Weak, nonatomic) Iboutlet UILabel*Counterlabel, @property (nonatomic, strong) Nstimer*timer;@end@implementationHmviewcontroller/** Start*/-(ibaction) start{//countdown 10 seconds, update the label display every second//Timer    /** Parameter Description 1. Time interval, double 2. Listens for clock-triggered objects 3. Call Method 4. UserInfo, which can be any object, usually passing nil 5. Repeats: Repeat /c7>*/Self.counterLabel.text=@"Ten"; //The Scheduledtimerwithtimeinterval method essentially creates a clock,//the mode to be added to the run loop is Defaultrunloopmode// ----------------------------------------------    //1>//Self.timer = [Nstimer scheduledtimerwithtimeinterval:1.0 target:self selector: @selector (updatetimer:) userinfo:@        "Hello timer" repeats:yes]; // ----------------------------------------------    //2> and 1 equivalence//Self.timer = [Nstimer timerwithtimeinterval:1.0 target:self selector: @selector (updatetimer:) Userinfo:nil Repeats : YES];//    //Add a timer to the run loop//    //mode: Default run-cycle mode//[[Nsrunloop Currentrunloop] AddTimer:self.timer Formode:nsdefaultrunloopmode]; // ----------------------------------------------    //3>Self.timer = [Nstimer timerwithtimeinterval:1.0target:self selector: @selector (updatetimer:) Userinfo:nil Repeats:yes]; //Add a timer to the run loop//mode: Nsrunloopcommonmodes running cycle mode (monitor scrolling mode)[[Nsrunloop Currentrunloop] AddTimer:self.timer formode:nsrunloopcommonmodes]; //[self updateTimer:self.timer];}/** Clock Update method*/- (void) Updatetimer: (Nstimer *) timer{//NSLog (@ "%s", __func__); //1. Remove the number from the label    intCounter =Self.counterLabel.text.intValue; //2. Determine if zero, if 0, stop clock    if(--counter <0) {        //Stop Clock[self pause]; //Prompt user, prompt box//Uialertview *alert = [[Uialertview alloc] initwithtitle:@ "Start" message:@ "Start ..." delegate:self Cancelbuttont itle:@ "Cancel" otherbuttontitles:@ "OK", @ "haha", nil];////[alert show];[[[Uialertview alloc] Initwithtitle:@"Start"Message@"Here we go ." Delegate: Self Cancelbuttontitle:@"Cancel"Otherbuttontitles:@"Determine",@"haha", nil] show]; } Else {        //CTRL + I//3. Modify the numbers and update the UISelf.counterLabel.text = [NSString stringWithFormat:@"%d", counter]; }}/** Pause*/-(ibaction) pause{//stop Clock, invalidate is the only way to stop the clock//once the Invalidate method is called, the timer is invalid, and if you start the clock again, you need to re-instantiate[Self.timer invalidate];}#pragmaMark-alertview Proxy Method-(void) Alertview: (Uialertview *) Alertview Clickedbuttonatindex: (nsinteger) buttonindex{NSLog (@"%ldaaa-------", (Long) buttonindex);}@end

iOS Sixth day (2:10 seconds Countdown)

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.