欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

iOS实现代码只执行一次

程序员文章站 2023-11-27 19:39:28
ios实现代码只让执行一次 - (void)viewdidload { [super viewdidload]; // do any addition...

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];
}