zoukankan      html  css  js  c++  java
  • 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:0]; for (int i=0; i<5; i++) { int random=arc4random()%10000+1;//1~10000 NSTimeInterval deltTime = (NSTimeInterval)random; futureDate = [[NSDate date] dateByAddingTimeInterval:deltTime]; //未来时间 [timeArr addObject:futureDate]; } timerTableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, 480) 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 1; } -(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 % 60; NSInteger minutes = (leftSeconds / 60) % 60; NSInteger hours = leftSeconds / (60 * 60); if (hours==0) { 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]; }
  • 相关阅读:
    css自适应
    css居中
    js生成签名
    javascript与Android、IOS交互
    js截取路径参数
    js date对象
    js判断设备、浏览器类型
    live555实践
    关于django
    mysql的基本知识
  • 原文地址:https://www.cnblogs.com/hl666/p/3655272.html
Copyright © 2011-2022 走看看