****************10秒倒计时

#import "HMViewController.h"

@interface HMViewController () <UIAlertViewDelegate>

@property (weak, nonatomic) IBOutlet UILabel *counterLabel;

@property (nonatomic, strong) NSTimer *timer;
@end @implementation HMViewController /** 开始 */
- (IBAction)start
{
// 倒计时10秒,每秒更新一下Label的显示
// 计时器
/**
参数说明
1. 时间间隔,double
2. 监听时钟触发的对象
3. 调用方法
4. userInfo,可以是任意对象,通常传递nil
5. repeats:是否重复
*/
self.counterLabel.text = @""; // scheduledTimerWithTimeInterval 方法本质上就是创建一个时钟,
// 添加到运行循环的模式是DefaultRunLoopMode
// ----------------------------------------------
// 1>
// self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateTimer:) userInfo:@"hello timer" repeats:YES]; // ----------------------------------------------
// 2> 与1等价
// self.timer = [NSTimer timerWithTimeInterval:1.0 target:self selector:@selector(updateTimer:) userInfo:nil repeats:YES];
// // 将timer添加到运行循环
// // 模式:默认的运行循环模式
// [[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSDefaultRunLoopMode]; // ----------------------------------------------
// 3>
self.timer = [NSTimer timerWithTimeInterval:1.0 target:self selector:@selector(updateTimer:) userInfo:nil repeats:YES];
// 将timer添加到运行循环
// 模式:NSRunLoopCommonModes的运行循环模式(监听滚动模式)
[[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];
//[self updateTimer:self.timer];
} /** 时钟更新方法 */
- (void)updateTimer:(NSTimer *)timer
{
// NSLog(@"%s", __func__);
// 1. 取出标签中的数字
int counter = self.counterLabel.text.intValue; // 2. 判断是否为零,如果为0,停止时钟
if (--counter < ) {
// 停止时钟
[self pause]; // 提示用户,提示框
// UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"开始" message:@"开始啦......" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", @"哈哈", nil];
//
// [alert show];
[[[UIAlertView alloc] initWithTitle:@"开始" message:@"开始啦......" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", @"哈哈", nil] show];
} else {
// CTRL + I
// 3. 修改数字并更新UI
self.counterLabel.text = [NSString stringWithFormat:@"%d", counter];
}
} /** 暂停 */
- (IBAction)pause
{
// 停止时钟,invalidate是唯一停止时钟的方法
// 一旦调用了invalidate方法,timer就无效了,如果再次启动时钟,需要重新实例化
[self.timer invalidate];
} #pragma mark - alertView代理方法
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(@"%ldaaa-------", (long)buttonIndex);
} @end

IOS第六天(2:10秒倒计时)的更多相关文章

  1. js实现模拟自动点击按钮,并且在10秒倒计时之后疯狂点击

    需求来自于csdn问答,可以利用这个原理做秒杀抢单外挂. 代码示例如下: <html> <head> <meta charset="utf-8"/&g ...

  2. 网页上10秒倒计时,完了后就自动跳转到另一个网页上html代码

    用html代码的话就这样: <meta http-equiv="Refresh" content="10;URL=http://www.baidu.com" ...

  3. js 10秒倒计时 功能

    请等待<span id=</span>秒 <script type="text/javascript"> function run(){ var s ...

  4. iOS “获取验证码”按钮的倒计时功能

    iOS 的倒计时有多种实现细节,Cocoa Touch 为我们提供了 NSTimer 类和 GCD 的dispatch_source_set_timer方法去更加方便的使用计时器.我们也可以很容易的的 ...

  5. js10秒倒计时鼠标点击次数统计

    <html> <head> <meta charset="utf-8"/> <script type="text/javascr ...

  6. js 10秒钟倒计时

    第一个: <html> <head> <meta http-equiv="Content-Type" content="text/html; ...

  7. js实现60秒倒计时效果(使用了jQuery)

    今天碰到要实现一个类似那种短信验证码60秒倒计时的需求,好久不写js,有点手生.把代码记录下,方便后续查阅. 这里我用了jQuey,毕竟写起来简洁点.下面直接看效果和代码. 一.效果          ...

  8. iOS 在cell中使用倒计时的处理方法(新)

    一.前言 之前的文章iOS 在cell中使用倒计时的处理方法得到大量的支持, 在这先感谢大家的支持. 但是也收到不少人的回复表示不会用, 需要一一解答, 由于之前写的时候没有使用Markdown编辑, ...

  9. uni验证码60秒倒计时

    其实要实现这个功能原理非常简单,就是setInterval+setTimeout+clearInterval结合使用,首先在data里定义一个变量second,初始值为60,然后在setInterva ...

随机推荐

  1. [Android Pro] 监听WIFI 打开广播

    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> <uses-perm ...

  2. .tar.bz2文件解压命令

    从网络上下载到的源码包, 最常见的是 .tar.gz 包, 还有一部分是 .tar.bz2包 要解压很简单 : .tar.gz     格式解压为          tar   -zxvf   xx. ...

  3. FreeMarker备忘

    以下内容全部是网上收集: FreeMarker的模板文件并不比HTML页面复杂多少,FreeMarker模板文件主要由如下4个部分组成: ,文本:直接输出的部分 ,注释:<#-- ... --& ...

  4. svn 结合rsync 的代码发布系统

    由开发提交到测试环境,经测试,在由运维统一上线.试验需求一台测试服务器,一台线上(生产环境)服务器.测试服务器上跑svn是开发用于代码管理,而线上跑的svn是运维用来代码上线的.结合rsync保持测试 ...

  5. 5.建造者模式(Builder Pattern)

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  6. Linux下Gcc生成和使用静态库和动态库详解

    参考文章:http://blog.chinaunix.net/uid-23592843-id-223539.html 一.基本概念 1.1什么是库 在windows平台和linux平台下都大量存在着库 ...

  7. 10年程序员谈.Net程序员的职业规划(图/文) (转载)

    转载地址:http://www.cnblogs.com/donghongtao/p/3611623.html

  8. [图文详解] Sublime Text在Windows/Ubuntu/Mac OSX中配置使用CTags

    很开发者都在找Sublime Text中函数转跳的功能,这个是软件自身没有的功能,要靠CTags这个插件配合CTags的可执行程序的实现的.按照我的理解是CTags扫描索引你的项目文件,然后subli ...

  9. PHP自毁程序

    <?php // +---------------------------------------------------------------------- // | Kill!! // | ...

  10. poj 1753

    翻转棋,注意是翻转周围四个的,不是整行列的  汗-_-! 哥的代码风还是不错的 二进制储存状态 Sample Input bwwb bbwb bwwb bwww Sample Output 4 #in ...