IOS6学习笔记(四)

时间:2021-12-20 14:59:47

1.GCD设置一个timer计时器

- (void)awakeFromNib {

  __weak id weakSelf = self;

  double delayInSeconds = 0.25;

   _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,dispatch_get_main_queue());

  dispatch_source_set_timer(_timer, dispatch_walltime(NULL, 0),(unsigned)(delayInSeconds * NSEC_PER_SEC), 0);

  dispatch_source_set_event_handler(_timer, ^{

    [weakSelf updateValues];

  });

  dispatch_resume(_timer);

}

- (void)updateValues {

}

- (void)dealloc {

  dispatch_source_cancel(_timer);

}