创建和传值
NSMutableDictionary *dic = [NSMutableDictionary dictionary];
[dic setObject:testImgView forKey:@"test"];
[dic setObject:@"2" forKey:@"type"];
[dic setObject:strY forKey:@"y"];
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:1.5 target:self selector:@selector(onTimer:) userInfo:dic repeats:NO];
[[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
}
- (void)onTimer:(NSTimer *)timer {
销毁
[timer invalidate];
timer = nil;
_adNum = 3;
_adTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timerAction) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:_adTimer forMode:NSRunLoopCommonModes];
}
- (void)timerAction{
if (_adNum == 1) {
[self timerClock];
}else{
_adNum--;
}
NSLog(@"timer run --%d-",_adNum);
}
- (void)timerClock{
[_adTimer invalidate];
_adTimer = nil;
}
- (void)dealloc{
[_adTimer invalidate];
_adTimer = nil;
NSLog(@"************ dealloc ***************");
}