//
// 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 倒计时的更多相关文章

  1. iOS 倒计时NSTimer

    项目中可能会遇到有些倒计时的地方 比方 手机验证的时候,验证码一般都会有一个时间限制,此时在输入验证码的地方就须要展示一个倒计时 详细实现方式是使用了iOS 自带的 NSTimer 上代码 首先新建 ...

  2. 小程序实现倒计时:解决ios倒计时失效(setInterval失效)

    在使用之前需要先在page页引入wxTimer.js文件(这里我将文件放在/utils) let timer = require('../../utils/wxTimer.js'); 然后就可以使用啦 ...

  3. iOS倒计时

    现在开发基本上都有发送验证码,倒计时,下面说一种 #import <UIKit/UIKit.h> @interface UIButton (CountDown) -(void)startT ...

  4. iOS 倒计时的一种实现

    1.view [self performSelectorInBackground:@selector(thread) withObject:nil]; - (void)thread { ;i>= ...

  5. iOS - 倒计时封装

    +(NSString *)countdownStartTime:(NSString *)startTime{ NSString *TIME = [startTime substringToIndex: ...

  6. iOS倒计时button闪烁

    v _button.titleLabel.text = [NSString stringWithFormat:@"%d后重发",t]; [_button setTitle:[NSS ...

  7. iOS炫酷动画图案、多种选择器、网络测速、滑动卡片效果等源码

    iOS精选源码 对网络进行测速 自实现大标题,配合原生骨架屏demo 简单方便的pickerVIew记录数据 LZPickerView 科技风绘制组件,简单快速"画"出炫酷图案 R ...

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

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

  9. iOS 短信验证码倒计时按钮的实现

    验证码倒计时按钮的应用是非常普遍的,本文介绍了IOS实现验证码倒计时功能,点击获取验证码,进入时间倒计时,感兴趣的小伙伴们可以参考一下: 实现思路: 创建按钮,添加点击方法: 用NSTimer定时器, ...

随机推荐

  1. openstack安装记录(二)keystone安装

    先决条件 在你配置 OpenStack 身份认证服务前,你必须创建一个数据库和管理员令牌. 完成下面的步骤以创建数据库: 用数据库连接客户端以 root 用户连接到数据库服务器: $ mysql -u ...

  2. 如何让旧版IE浏览器认识HTML5元素

    <!--[if lt IE 9]> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js" ...

  3. 一个AVRUSB作品HID类

    最近为了HID类设备弄了半个把月.终于完成这个无线(红外)多媒体键盘,带鼠标功能.难就难在描述符上,不过在近4天的资料翻阅及多次的测试下,电脑不知道重启了多少次啊,的情况下 搞定了这个东西,大家可以看 ...

  4. jdk1.6下载页面

    http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-javase6-41940 ...

  5. RHEL 6.3使用CentOS yum源 (redhat yum安装失败)

    由于Redhat的yum在线更新是收费的,如果没有注册的话是不能使用的,即不能在线安装软件.所以yum install 命令每次都安装失败 下面介绍一种更改yum源的方式: 系统说明: 系统:Red ...

  6. linux中的strings命令简介

    摘自:http://blog.csdn.net/stpeace/article/details/46641069 linux中的strings命令简介 在linux下搞软件开发的朋友, 几乎没有不知道 ...

  7. [转]中英文停止词表(stopword)

    停止词,是由英文单词:stopword翻译过来的,原来在英语里面会遇到很多a,the,or等使用频率很多的字或词,常为冠词.介词.副词或连词等.如果搜索引擎要将这些词都索引的话,那么几乎每个网站都会被 ...

  8. ASP.Net MVC中数据库数据导出Excel,供HTTP下载

    本文来自:http://www.cnblogs.com/hipo/archive/2012/03/13/2394019.html 一.关于下载 一般对下载权限有没有限制,或安全性要求不高的情况下,基于 ...

  9. NGUI 3.5过程(三)Button button

    写在前面:     本文将创建一个主要的Button.而且编写脚本,响应点击事件. 欢迎大家纠错.拍砖.原创非常辛苦,如有转载,请注明出处. Button -- button 在NGUI 3.5 里, ...

  10. 【收藏】十大Webserver漏洞扫描工具

    如今有很多消息令我们感到Web的危急性,因此,当前怎样构建一个安全的Web环境成为网管员和安全管理员们义不容辞的责任.可是巧妇难为无米之炊,该选择哪些安全工具呢? 扫描程序能够在帮助造我们造就安全的W ...