NSTimer的用法
来源:互联网 发布:电脑怎么使用手机网络 编辑:程序博客网 时间:2024/06/10 09:20
iPhone为我们提供了一个很强大得时间定时器 NSTimer,它可以完成任何定时功能:
我们使用起来也很简单,只要记住三要素就可以,具体得三要素是:时间间隔NSTimeInterval浮点型,事件代理delegate和事件处理方法@selector();
就可以用
1+(NSTimer *)scheduledTimerWithTimeIn
2terval:(NSTimeInterval)ti target:(id)aTarget selector:(SEL)aSelector userInfo:(id)userInfo repeats:(BOOL)yesOrNo;
[/pre]来初始化一个 时间定时器
下面我写了一个很简单得例子:
-(void)initTimer
{
//时间间隔4NSTimeInterval timeInterval =1.0;
//定时器6NSTimer showTimer =[NSTimer scheduledTimerWithTimeInterval:maxShowTime
target:self
selector:@selector(handleMaxShowTimer:)
userInfo:nil
repeats:NO];
}
//触发事件13-(void)handleMaxShowTimer:(NSTimer *)theTimer
{
NSDateFormatter dateFormator =[[NSDateFormatter alloc] init];
dateFormator.dateFormat =@"yyyy-MM-dd HH:mm:ss";
NSString *date =[dateformater stringFromDate:[NSDate date]];
if([date isEqualToString:@"2010-11-09 23:59:59"])
{
UIAlertView *alert =[[UIAlertView alloc] initWithTitle:TITLE_NAME
message:@"现在马上就有新的一天了!"22delegate:self
cancelButtonTitle:nil
otherButtonTitles:CONFIRM_TITLE, nil];
[alert show];
[alert release];
}
[data release];
[dateFormator release];
}
我们使用起来也很简单,只要记住三要素就可以,具体得三要素是:时间间隔NSTimeInterval浮点型,事件代理delegate和事件处理方法@selector();
就可以用
1+(NSTimer *)scheduledTimerWithTimeIn
2terval:(NSTimeInterval)ti target:(id)aTarget selector:(SEL)aSelector userInfo:(id)userInfo repeats:(BOOL)yesOrNo;
[/pre]来初始化一个 时间定时器
下面我写了一个很简单得例子:
-(void)initTimer
{
//时间间隔4NSTimeInterval timeInterval =1.0;
//定时器6NSTimer showTimer =[NSTimer scheduledTimerWithTimeInterval:maxShowTime
target:self
selector:@selector(handleMaxShowTimer:)
userInfo:nil
repeats:NO];
}
//触发事件13-(void)handleMaxShowTimer:(NSTimer *)theTimer
{
NSDateFormatter dateFormator =[[NSDateFormatter alloc] init];
dateFormator.dateFormat =@"yyyy-MM-dd HH:mm:ss";
NSString *date =[dateformater stringFromDate:[NSDate date]];
if([date isEqualToString:@"2010-11-09 23:59:59"])
{
UIAlertView *alert =[[UIAlertView alloc] initWithTitle:TITLE_NAME
message:@"现在马上就有新的一天了!"22delegate:self
cancelButtonTitle:nil
otherButtonTitles:CONFIRM_TITLE, nil];
[alert show];
[alert release];
}
[data release];
[dateFormator release];
}
- NSTimer的用法
- NSTimer的用法
- NSTimer的用法
- NSTimer的用法
- NSTimer的用法 IOS
- NSTimer的一些用法
- NSTimer 的用法
- NSTimer的用法
- NSTimer的用法
- NSTimer定时器的简单用法/NSTimer Instance
- IOS开发 NSTimer的用法
- NSTimer和CADisplayLink的用法
- NSTimer和CADisplayLink的用法
- ios NSTimer的基本用法
- NSTimer用法
- iOS NSTimer的用法-下载进度显示
- IOS--NSTimer和CADisplayLink的用法
- IOS 中 NSTimer和CADisplayLink的用法
- iphone调用系统电话、浏览器、地图、邮件等
- SIM300 AT
- 类目(Category)概述
- 让一个UIImageView响应点击事件
- 黑马程序员学习笔记七——多线程
- NSTimer的用法
- SQL注入式攻击
- JSP 引擎工作原理
- uva 113 - Power of Cryptography
- com.opensymphony.xwork2.spring.SpringObjectFactory.getClassInstance
- .net c# 用代码来添加断点并且在Visual Studio输出窗口中显示自定义信息
- 完整详尽的二叉排序树性质及源码和注释 C语言 可直接运行
- android canvas的清空 !!!!!!头痛,,,,,,,哎
- ScrollView嵌套ListView时ListView的数据显示不全的解决方案