设为首页 加入收藏

TOP

object-c 日期总结(三)
2015-02-26 02:04:13 来源: 作者: 【 】 浏览:278
Tags:object-c 日期 总结
以使用任何对象,并且可以获得正在执行的消息中的对象引用(上面的selector参数)。这里使用字符串,但通常会使用字典或其他集合以支持更加复杂的活动。
参数六:repeats参数表示定时器是发送一次消息,还是根据第2个参数指定的时间间隔重复发送。
NSRunLoop *runLoop=[NSRunLoop currentRunLoop[;
[runLoop addTimer:timer forMode:NSDefaultRunLoopMode];
10秒钟后,定时器将会开始每隔两秒钟向应用发送task消息。
[timer invalidate];
/**
*定时器小例子
*/
#import "AppDelegate.h"
@implementation AppDelegate
@synthesize window=_window;
-(void)applicationDidFinishLaunching:(NSNotification *)aNotification{
NSDate *scheduledTime=[NSDate dateWithTimeIntervalSinceNow:10.0];
NSString *customUserObject=@"To demo userInfo";
NSTimer *timer=[[NSTimer alloc]initWithFireDate:scheduledTime
interval:2
target:self
selector:@selector(task)
userInfo:customUserObject
repeats:YES];
NSRunLoop *runLoop=[NSRunLoop currentRunLoop[;
[runLoop addTimer:timer forMode:NSDefaultRunLoopMode];
}
-(void)task:(id)sender{
NSTimer *localTimer=(NSTimer *)sender;
NSLog(@"Schedule task has executed with this user info :%@",[localTimer userInfo]);
}
@end
首页 上一页 1 2 3 下一页 尾页 3/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇C语言关键字 (二) 下一篇C中函数指针的用法

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: