iOS 倒计时
//
// RootViewController.m
// MyTimerDemo
//
// Created by huluo on 1/21/14.
// Copyright (c) 2014 bluemobi.cn. All rights reserved.
// #import "RootViewController.h" @interface RootViewController () @end @implementation RootViewController
{
UITableView *timerTableView;
NSMutableArray *timeArr; NSTimer *myTimer;
NSDate *startDate;
NSDate* futureDate;
} - (void)dealloc
{
[timerTableView release];
[timeArr release];
[myTimer invalidate];
[super dealloc];
} - (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor=[UIColor brownColor]; timeArr=[[NSMutableArray alloc]initWithCapacity:];
for (int i=; i<; i++) {
int random=arc4random()%+;//1~10000
NSTimeInterval deltTime = (NSTimeInterval)random;
futureDate = [[NSDate date] dateByAddingTimeInterval:deltTime]; //未来时间
[timeArr addObject:futureDate];
} timerTableView=[[UITableView alloc]initWithFrame:CGRectMake(, , , ) style:UITableViewStylePlain];
timerTableView.delegate=self;
timerTableView.dataSource=self;
[self.view addSubview:timerTableView]; myTimer=[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(refreshTime) userInfo:nil repeats:YES];
} #pragma mark ----tableView---- -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return ;
} -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [timeArr count];
} - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 50.0f;
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{ UITableViewCell* cell=(UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"cell"];
if(cell==nil)
{
cell=[[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"]autorelease]; }
NSDate *toDate=[timeArr objectAtIndex:indexPath.row];
startDate = [NSDate date];
long leftSeconds=[toDate timeIntervalSinceDate:startDate];
NSInteger seconds = leftSeconds % ;
NSInteger minutes = (leftSeconds / ) % ;
NSInteger hours = leftSeconds / ( * );
if (hours==) {
cell.textLabel.text = [NSString stringWithFormat:@"%02d:%02d", minutes, seconds];
}else{
cell.textLabel.text = [NSString stringWithFormat:@"%02d:%02d:%02d", hours, minutes, seconds];
} return cell;
} //刷新时间
-(void)refreshTime
{
startDate = [ [ NSDate date];
[timerTableView reloadData];
}
iOS 倒计时的更多相关文章
- iOS 倒计时NSTimer
项目中可能会遇到有些倒计时的地方 比方 手机验证的时候,验证码一般都会有一个时间限制,此时在输入验证码的地方就须要展示一个倒计时 详细实现方式是使用了iOS 自带的 NSTimer 上代码 首先新建 ...
- 小程序实现倒计时:解决ios倒计时失效(setInterval失效)
在使用之前需要先在page页引入wxTimer.js文件(这里我将文件放在/utils) let timer = require('../../utils/wxTimer.js'); 然后就可以使用啦 ...
- iOS倒计时
现在开发基本上都有发送验证码,倒计时,下面说一种 #import <UIKit/UIKit.h> @interface UIButton (CountDown) -(void)startT ...
- iOS 倒计时的一种实现
1.view [self performSelectorInBackground:@selector(thread) withObject:nil]; - (void)thread { ;i>= ...
- iOS - 倒计时封装
+(NSString *)countdownStartTime:(NSString *)startTime{ NSString *TIME = [startTime substringToIndex: ...
- iOS倒计时button闪烁
v _button.titleLabel.text = [NSString stringWithFormat:@"%d后重发",t]; [_button setTitle:[NSS ...
- iOS炫酷动画图案、多种选择器、网络测速、滑动卡片效果等源码
iOS精选源码 对网络进行测速 自实现大标题,配合原生骨架屏demo 简单方便的pickerVIew记录数据 LZPickerView 科技风绘制组件,简单快速"画"出炫酷图案 R ...
- iOS “获取验证码”按钮的倒计时功能
iOS 的倒计时有多种实现细节,Cocoa Touch 为我们提供了 NSTimer 类和 GCD 的dispatch_source_set_timer方法去更加方便的使用计时器.我们也可以很容易的的 ...
- iOS 短信验证码倒计时按钮的实现
验证码倒计时按钮的应用是非常普遍的,本文介绍了IOS实现验证码倒计时功能,点击获取验证码,进入时间倒计时,感兴趣的小伙伴们可以参考一下: 实现思路: 创建按钮,添加点击方法: 用NSTimer定时器, ...
随机推荐
- python运维开发(十二)----rabbitMQ、pymysql、SQLAlchemy
内容目录: rabbitMQ python操作mysql,pymysql模块 Python ORM框架,SQLAchemy模块 Paramiko 其他with上下文切换 rabbitMQ Rabbit ...
- bzoj 2648 SJY摆棋子 kd树
题目链接 初始的时候有一些棋子, 然后给两种操作, 一种是往上面放棋子. 另一种是给出一个棋子的位置, 问你离它最近的棋子的曼哈顿距离是多少. 写了指针版本的kd树, 感觉这个版本很好理解. #inc ...
- Python爬虫实战(4):豆瓣小组话题数据采集—动态网页
1, 引言 注释:上一篇<Python爬虫实战(3):安居客房产经纪人信息采集>,访问的网页是静态网页,有朋友模仿那个实战来采集动态加载豆瓣小组的网页,结果不成功.本篇是针对动态网页的数据 ...
- 验证角谷猜想(hd1279)
验证角谷猜想 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- C语言基础06
函数: 一组特定功能的代码段,之所以使用函数,为了在文件多处需要同一段代码时可以多次重复利用,减少代码冗余. //函数的声明 返回值类型 函数名称 ( 数据类型 形参1,数据类型 ,形参2 ) ; / ...
- nginx的请求接收流程(一)
今年我们组计划写一本nginx模块开发以及原理解析方面的书,整本书是以open book的形式在网上会定时的更新,网址为http://tengine.taobao.org/book/index.htm ...
- 将一段含有0的字符数组赋给string
string有个成员函数,assign() 可以这样: string str; str.assign(temp, sizeof(temp));
- Windows服务程序的原理及实现(服务分为WIN32服务和系统服务)
今天给大家讲下怎样做一个服务程序...本来是想详细讲的,不过写着写着累得要命..很多 地方就没详细...不过代码我加了点注...如果还有一些不明白的自己查下MSDN......便宜 环境,,VC++6 ...
- Codeforces #344 Div.2
Codeforces #344 Div.2 Interview 题目描述:求两个序列的子序列或操作的和的最大值 solution 签到题 时间复杂度:\(O(n^2)\) Print Check 题目 ...
- 充分利用CPU高速缓存,提高程序效率(原理篇)
提高程序效率应该充分利用CPU的高速缓存.要想编写出对CPU缓存友好的程序就得先明白CPU高速缓存的运行机制. i5-2400S: 1.有三级缓存分别为 32k(数据.指令缓存分开,分为32k),25 ...