Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -(void)btnClick:(id)sender
- {
- NSLog(@"btnClick");
- dispatch_queue_t queue=dispatch_get_global_queue(0, 0);
- dispatch_source_t timer=dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
- dispatch_source_set_timer(timer, dispatch_walltime(NULL, 0), 2*NSEC_PER_SEC, 1*NSEC_PER_SEC);
- dispatch_source_set_event_handler(timer, ^{
- dispatch_async(dispatch_get_main_queue(), ^{
- self.label1.text=[NSString stringWithFormat:@"%d", arc4random_uniform(1000000)];
- });
- });
- dispatch_resume(timer);
- }
- //Define member varialbe for timer in header file
- NSTimer* timerForLocationUpdate;
- //Call createTimer to create timer that will execute in each 1 min
- - (void) createTimer
- {
- timerForLocationUpdate = [NSTimer scheduledTimerWithTimeInterval:60 /*Number of seconds*/
- target:self
- selector:@selector(updateLocation)
- userInfo:nil
- repeats:YES];
- [[NSRunLoop currentRunLoop] addTimer:timerForLocationUpdate
- forMode:NSRunLoopCommonModes];
- }
- //Method is called in each 1 min
- - (void) updateLocation
- {
- }
- NSTimer *t = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(yourMethod) userInfo:nil repeats:YES];
- NSRunLoop *runner = [NSRunLoop currentRunLoop];
- [runner addTimer:t forMode: NSDefaultRunLoopMode];
- -(void)yourMethod{
- Self.label1.text = [NSString stringWithFormat:@"%d", arc4random_uniform(1000000)];
- }
- -(void)btnClick:(id)sender
- {
- NSLog(@"btnClick");
- static dispatch_source_t timer;
- dispatch_queue_t queue=dispatch_get_global_queue(0, 0);
- timer=dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
- dispatch_source_set_timer(timer, dispatch_walltime(NULL, 0), 2*NSEC_PER_SEC, 1*NSEC_PER_SEC);
- dispatch_source_set_event_handler(timer, ^{
- dispatch_async(dispatch_get_main_queue(), ^{
- self.label1.text=[NSString stringWithFormat:@"%d", arc4random_uniform(1000000)];
- });
- });
- dispatch_resume(timer);
- }
Add Comment
Please, Sign In to add comment