- (void)viewDidLoad {
[super viewDidLoad];
_timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timeEvent:) userInfo:nil repeats:YES];
}
- (void)timeEvent:(NSTimer *)sender{
NSLog(@"&sender before = %p",&sender);
NSLog(@"sender before = %p",sender);
[sender invalidate];
sender = nil;
NSLog(@"&sender after = %p",&sender);
NSLog(@"&_timer = %p",&_timer);
NSLog(@"sender after = %p",sender);
NSLog(@"_timer = %p",_timer);
}
NSLog(@"sender before = %p",&sender); 这个是指针的地址
NSLog(@"sender before = %p",sender); 这个是指针指向值的地址
打印结果:
&sender before = 0x7fff5dc516f8
sender before = 0x6000003615c0
&sender after = 0x7fff5dc516f8
&_timer = 0x7ff586707d88
sender after = 0x0
_timer = 0x6000003615c0
结论:将定时器事件中参数置空,但是不能将self.timer的地址置空。