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定时器, ...
随机推荐
- eclipse 常用的一些设置
1.行长度设置 http://blog.csdn.net/janronehoo/article/details/10047937 2.字体 windows -> preference -> ...
- 如何自定义MVC控件?
今天公司要写学习总结,想着想着还是先写一篇关于MVC内部什么东东的博客整理整理再发表吧,一举两得. 之前写过了路由.过滤器等.今天就研究一下怎么自定义MVC控件吧. 本人技术小菜,不喜勿喷.....( ...
- flex——dictionary跟Object的区别与遍历
AS3中Object和 Dictionary都可以用来保存key-value形式的数据,Dictionary类和Object唯一的区别在于:Dictionary对象可以使用非字符串作为键值对的键.例如 ...
- awk(流程控制、内置变量、内置函数、数组)
摘自:http://bbs.51cto.com/thread-883948-1-1.html awk(流程控制.内置变量.内置函数.数组) ... 参考其他的资料,给大家看看.一.awk流程控制语句 ...
- Linux 下如何安装软件?
http://zhidao.baidu.com/link?url=OkQCOZtVMXhasC8x9zFTZOumsFKf0WW25Ckr2wBF1xO08EsjrBpnMaTBlIAUYdxZ408 ...
- linux使用FIO测试磁盘的iops
FIO是测试IOPS的非常好的工具,用来对硬件进行压力测试和验证,支持13种不同的I/O引擎,包括:sync,mmap, libaio, posixaio, SG v3, splice, null, ...
- Dima and Salad(完全背包)
Dima and Salad time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- 运用Autoconf和Automake生成Makefile的学习之路
作为Linux下的程序开发人员,大家一定都遇到过Makefile,用make命令来编译自己写的程序确实是很方便.一般情况下,大家都是手工写一个简单Makefile,如果要想写出一个符合自由软件惯例的M ...
- jQuery的主要用法
一.选择网页元素jQuery的基本设计和主要用法,就是"选择某个网页元素,然后对其进行某种操作".这是它区别于其他函数库的根本特点. 使用jQuery的第一步,往往就是将一个选择表 ...
- Android开发环境的搭建之(四)虚拟设备AVD的基本配置
配置Android系统语言包为中文简体.点击导航栏左数第二个“菜单”图标 选择“System settings”. 选择“Language & Input” 选择“Language” 选择“中 ...