Rumah > Soal Jawab > teks badan
#import "MyViewController.h"
@interface MyViewController ()
{
NSTimer *_timer;
}
@end
@implementation MyViewController
- (void)dealloc
{
[_timer invalidate];
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
_timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(changeCountdownTime) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:_timer forMode:NSRunLoopCommonModes];
}
- (void)changeCountdownTime
{
// do something
}
- (void)back
{
[self.navigationController popViewControllerAnimated:YES];
}
PHP中文网2017-05-02 09:37:06
Kaedah penulisan yang disyorkan ialah menulis [_timer invalidate] dahulu; dan kemudian tulis _timer = nil; sebelum memusnahkan vc dan memanggil kaedah -dealloc.