iOS实现代码只执行一次
投稿:hebedich
本文给大家分享的是在iOS中控制代码在整个软件生命周期中只运行一次的代码,有需要的小伙伴可以参考下。
iOS实现代码只让执行一次
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. [self performSelector:@selector(wangmumu:) withObject:@"100" afterDelay:1]; } - (void) wangmumu:(NSString *)han{ static dispatch_once_t hanwanjie; //只执行一次 dispatch_once(&hanwanjie, ^{ NSLog(@"12345678910"); }); int niha = [han intValue] - 1; if (niha == 10) { return; } [self performSelector:@selector(hanwanjie:) withObject:[NSString stringWithFormat:@"%d",niha] afterDelay:1]; }