****************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. Greedy:Packets(POJ 1017)

    装箱问题1.0 题目大意:就是一个工厂制造的产品都是正方形的,有1*1,2*2,3*3,4*4,5*5,6*6,高度都是h,现在要包装这些物品,只能用6*6*h的包装去装,问你怎么装才能使箱子打到最小 ...

  2. codeforces 459C Pashmak and Buses 解题报告

    题目链接:http://codeforces.com/problemset/problem/459/C 题目意思:有 n 个 students,k 辆 buses.问是否能对 n 个students安 ...

  3. fedora 添加其他操作系统到 GRUB 2 菜单

    # yum install os-prober # grub2-mkconfig -o /boot/grub2/grub.cfg

  4. ping 有端口的ip

    使用工具 tcping 使用方法,将此工具放在C:/Windows/System32 目录下, 在cmd 中: tcping 127.0.0.1 8080

  5. php 工厂模式

    <body> <?php //设计模式:工厂模式 /* class YunSuan { public $a; public $b; function Jia() { return ( ...

  6. InnoDB引擎的索引和存储结构

    在Oracle 和SQL Server等数据库中只有一种存储引擎,所有数据存储管理机制都是一样的.而MySql数据库提供了多种存储引擎.用户可以根据不同的需求为数据表选择不同的存储引擎,用户也可以根据 ...

  7. php变量的几种写法

    一.最简单的 $str = 'Hello World!'; 二.来个变种 $str = 'good'; $good = 'test'; $test = 'Hello World!'; echo $$$ ...

  8. Java Hour 53 HQL

    上回写到一个一个最基本的HQL 查询语句写出来都没有什么自信,这一课时就补上HQL 相关的知识. 这种东西笔者最喜欢的官方的原版说明文档了. http://docs.jboss.org/hiberna ...

  9. hdu 5115 区间dp ***

    题意:有n只狼,每只狼有两种属性,一种攻击力一种附加值,我们没杀一只狼,那么我们受到的伤害值为这只狼的攻击值与它旁边的两只狼的附加值的和,求把所有狼都杀光受到的最小的伤害值. 枚举中间k作为最后杀死的 ...

  10. 计数排序算法——时间复杂度O(n+k)

    计数排序 计数排序是一个非基于比较的排序算法,该算法于1954年由 Harold H. Seward 提出.它的优势在于在对一定范围内的整数排序时,它的复杂度为Ο(n+k)(其中k是整数的范围),快于 ...