initWithFireDate 方法参数说明。典型的selector 与 id userinfo 使用示例
来源:互联网 发布:淘宝省钱app有哪些 编辑:程序博客网 时间:2024/06/06 07:07
- (id)initWithFireDate:(NSDate *)date interval:(NSTimeInterval)seconds target:(id)target selector:(SEL)aSelector userInfo:(id)userInfo repeats:(BOOL)repeats
date: 第一次 fire 时间
interval:重复fire的时间间隔,适用于repeats为YES
target:表示发送的对象,如self
aSelector:方法选择器,在时间间隔内,选择调用一个实例方法
userInfo:id类型,可以为空。可以在aSelector中强转回之前传入的类型。
repeats:当YES时,定时器会不断循环直至失效或被释放,当NO时,定时器会循环发送一次就失效。
/** * 启动一个NSTimer */-(void)timerTest{NSNumber* testValue = [NSNumber numberWithInt:100];NSDate* fireDate = [[NSDate alloc] initWithTimeIntervalSinceNow:5]; //5s 后 第一次 fireNSTimer* testTimer = [[NSTimer alloc] initWithFireDate:fireDate interval:5 target:self selector:@selector(timerSelector:) userInfo:testValue repeats:YES];[[NSRunLoop currentRunLoop] addTimer:testTimer forMode:NSDefaultRunLoopMode];}/** * NSTimer 执行函数 */-(void)timerSelector:(id)sender{int value = [(NSNumber*)[sender userInfo] intValue];//取回之前传入的数据NSLog(@"timerTest value: %d", value);//略...}
---- 参考内容:
请教,NSTimer怎么用?
-----
initWithFireDate:interval:target:selector:userInfo:repeats:
Initializes a new NSTimer object using the specified object and selector.
- (id)initWithFireDate:(NSDate *)date interval:(NSTimeInterval)seconds target:(id)target selector:(SEL)aSelector userInfo:(id)userInfo repeats:(BOOL)repeats
Parameters
date
The time at which the timer should first fire.
seconds
For a repeating timer, this parameter contains the number of seconds between firings of the timer. If seconds is less than or equal to0.0, this method chooses the nonnegative value of 0.1 milliseconds instead.
target
The object to which to send the message specified by aSelector when the timer fires. The target object is retained by the timer and released when the timer is invalidated.
aSelector
The message to send to target when the timer fires. The selector must have the following signature:
- (void)timerFireMethod:(NSTimer*)theTimer
The timer passes itself as the argument to this method.
userInfo
Custom user info for the timer. The object you specify is retained by the timer and released when the timer is invalidated. This parameter may benil.
repeats
If YES, the timer will repeatedly reschedule itself until invalidated. IfNO, the timer will be invalidated after it fires.
Return Value
The receiver, initialized such that, when added to a run loop, it will fire at date and then, if repeats isYES, every seconds after that.
Discussion
You must add the new timer to a run loop, using addTimer:forMode:. Upon firing, the timer sends the message aSelector to target. (If the timer is configured to repeat, there is no need to subsequently re-add the timer to the run loop.)
Availability
- Available in iOS 2.0 and later.
Related Sample Code
- TableViewSuite
Declared In
NSTimer.h
- initWithFireDate 方法参数说明。典型的selector 与 id userinfo 使用示例
- NSTimer scheduledTimerWithTimeInterval与timerWithTimeInterval、initWithFireDate的区别
- 多个参数的selector参数说明
- [FFmpeg]ffmpeg各类参数说明与使用示例
- iOS: NSNotification的方法userInfo
- @selector 使用与说明待补充
- Android ImageButton 使用Selector的简单示例
- @selector 里面的方法名加参数
- @selector方法有多个参数时的写法
- iOS: NSNotificationCenter的方法postNotificationName:object:userInfo:
- iOS: NSNotification的方法notificationWithName:object:userInfo:
- 递归的典型示例
- AOP典型应用:自动打印方法参数与返回值
- iOS的绘图方法使用和参数的说明
- ios UIBezierPath贝塞尔曲线的常用方法与参数说明
- 关于Selector方法需要多个参数的问题解决方法
- SQL计算困难的典型示例与点评
- Consumer使用示例与配置简要说明
- ubuntu 下交叉编译器arm-linux-gcc-4.3.2.tar.tgz的安装
- 电能质量监测装置人机界面设计总结(5)
- 读《如何阅读一本书》的小感想及笔记
- js正则表达式实例(汇总)
- 杨辉三角形源码
- initWithFireDate 方法参数说明。典型的selector 与 id userinfo 使用示例
- vim 用lookupfile插件报错E117
- POJ 2942 点的双连通分量
- 黑马程序员学习笔记之九(交通灯管理系统学习)
- Myeclipse报的是严重: Socketaccept failed
- Jquery图片浏览
- 周立波实意搞慈善 沈顺坤高举双手把他赞
- Java程序设计实验2
- NYOJ-421 打扑克【模拟】