//
// 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. 使用Python管理Azure(1):基础配置

    Azure提供了丰富的Python SDK来对Azure进行开发管理,包括使用Azure的开源框架在Azure上创建web应用程序,对Azure的虚拟机,存储等进行管理,本系类会简单介绍如何在ASM和 ...

  2. 定制化Azure站点Java运行环境(2)

    Azure Website上发布Java web应用 在Azure站点上发布Java Web应用非常简单,可以使用git从源代码发布,也可以使用FTP/FTPs直接发布,本节介绍FTP方式. 准备好你 ...

  3. android的edittext输入长度

    http://blog.csdn.net/uyu2yiyi/article/details/6329738 http://flysnow.iteye.com/blog/828415/ http://s ...

  4. 【Linux CentOS 在虚拟机中XShell出现: (port 22): Connection failed.】

    原因:没安装openssh-server组件!!!!!!!!!! 解决办法:yum install openssh-server 查看openssh-server是否启动: $:ps -ef |gre ...

  5. Windows Azure 的开源 DNA

    去年年底,第二期微软云加速器在中国正式启动,17 家创业公司入选.依靠云计算的 HTML 5 专业富媒体动画平台 Mugeda(乐享云)是其中之一.微软云加速器为创业公司提供大量支持,但 Mugeda ...

  6. poj 3254 Corn Fields_状态压缩dp

    感谢:http://www.cnblogs.com/ka200812/archive/2011/08/11/2135607.html 让我搞懂了. #include <iostream> ...

  7. OpenStack core components CLI快速调用API

    1,openStack core components CLI 使用自身参数执行;

  8. pushMeBaby,github链接

    https://github.com/stefanhafeneger/PushMeBaby

  9. android中控件公用产生的冲突的解决办法

    1.ViewPager嵌套HorizontalScrollView滑动冲突的解决办法,重写ViewPager public class ZdyViewPage extends ViewPager { ...

  10. 【csdn】文章很好 - system函数遇到的问题

    system函数遇到的问题http://blog.csdn.net/yangzhenzhen/article/details/51505176