//
// 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. C函数指针简单用例

    (1)函数指针:可以指向 一类 固定形参类型和返回值类型 的函数 的指针声明:int fun(int, int)    ||    \/int (*pfun)(int, int) pfun就是函数指针 ...

  2. TensorFlow深度学习笔记 Tensorboard入门

    转载请注明作者:梦里风林 Github工程地址:https://github.com/ahangchen/GDLnotes 欢迎star,有问题可以到Issue区讨论 官方教程: https://ww ...

  3. MYSQL SQL Server 事务

    开始: start transaction;   #   一定要有这个 ‘;’ 号. 注意: MYSQL  用的是快照隔离.就是说一个连接在修改的时候别的连接还是可以查询的. 例子: create t ...

  4. SQL Server 控制锁升级

    背景知识: 锁升级的路线图.行--> 页 --> 区(extent)-->区(表分区)--> 表: alter table 控制锁的升级行为: 1.table SQL Serv ...

  5. #include <boost/shared_array.hpp>

    共享数组 共享数组的行为类型于共享指针.关键不同在于共享数组在析构时,默认使用delete[]操作符来释放所含的对象.因为这个操作符只能用于数组对象,共享数组必须通过动态分配的数组的地址来初始化.共享 ...

  6. 全国计算机等级考试二级教程-C语言程序设计_第2章_C程序设计的初步知识

    正负号与被除数一致. 3 % (-5) == 3 (-3) % 5 == -3 不用求余运算符,求出余数. int x, y; 答:x - x / y * y; const int i = 10; c ...

  7. VMware虚拟机与主机联通及配置上网

    vmware版本:10.0.0 build-1295980,安装redhat enterprise linux 5.8 一.物理机与虚拟机联通,但不联网 1.虚拟网络VMnet1设置: 此时,物理主机 ...

  8. IIS中如何建立FTP服务

    文件传输协议 (FTP) 是一个标准协议,可用来通过 Internet 将文件从一台计算机移到另一台计算机.这些文件存储在运行 FTP 服务器软件的服务器计算机上.然后,远程计算机可以使用 FTP 建 ...

  9. 【C#】开发可以可视化操作的windows服务

    使用C#开发自定义windows服务是一件十分简单的事.那么什么时候,我们需要自己开发windows服务呢,就是当我们需要计算机定期或者一直执行我们开发的某些程序的时候.这里我以一个WCF的监听服务为 ...

  10. c# 读取IntPtr 中的数据

    c++的写法是这样的:LRESULT CPictureQueryDlg::OnQueryPicNty(WPARAM wp, LPARAM lp){EnableWindow(TRUE); BYTE *p ...