****************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. TinyMCE textarea 输入框外部程序动态修改方法

    TinyMCE textarea 输入框外部程序动态修改方法 Public Function C2IE_TINYMCE(ByVal id As String, ByVal value As Strin ...

  2. ssm操作控制台输出sql语句 log4j.properties

    # Configures Log4j for Tomcat and Sakai # use "A" for log in with catalina.out (actually s ...

  3. mybatis随机生成可控制主键的方式

    mybatis生成的主键,一般都是用数据库的序列,可是还有不同的写法,比如: 一.NUMBER类型的主键 <insert id="insertPeriodical" para ...

  4. discuz 学习

    一.Discuz首页“今日”“昨日”“欢迎新会员”等文字删除添加 搜索templeta/default/forum/discuz.htm   (使用非默认模版的请修改当前使用模版的discuz.htm ...

  5. ios 7.1.2 拍照声音

    打开进入文件系统(越狱)目录:/System/Library/Frameworks/MediaToolbox.framework , 重命名文件 RegionalSystemSoundsThatSha ...

  6. IBM V7000

    IBM_V7000 http://www.tuicool.com/articles/7vI7ja http://www.ibm.com/support/knowledgecenter/en/ST3FR ...

  7. MVC @helper (转载)

    转载地址:http://gaoling386.blog.163.com/blog/static/5404602420130595842894/ ASP.NET MVC 3支持一项名为“Razor”的新 ...

  8. 蓝牙4.0——Android BLE开发官方文档翻译

    ble4.0开发整理资料_百度文库 http://wenku.baidu.com/link?url=ZYix8_obOT37JUQyFv-t9Y0Sv7SPCIfmc5QwjW-aifxA8WJ4iW ...

  9. hdu 2199:Can you solve this equation?(二分搜索)

    Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  10. hdu 1166 线段树单点更新

    等线段树复习完再做个总结 1101 2 3 4 5 6 7 8 9 10Query 1 3Add 3 6Query 2 7Sub 10 2Add 6 3Query 3 10End Case 1:633 ...