Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

calling method repeatedly after 3 seconds time interval in background

I have gone through many sites but still no answer.

I have a method suppose void xyz(), which will get called automatically from a View Controller after every 3 seconds.

I have no idea what to use, do I have to use NSThread or PerformSelector.

like image 857
Vizllx Avatar asked Jan 27 '26 17:01

Vizllx


2 Answers

Call this method from ViewDidLoad method.ViewDidLoad will when your view will be appear in iPhone device or Simulator.

[NSTimer scheduledTimerWithTimeInterval:3.0f target:self selector:@selector(runMethod) userInfo:nil repeats:YES];


    -(void)runMethod

    {

    }
like image 62
Gajendra Rawat Avatar answered Jan 29 '26 07:01

Gajendra Rawat


Something like this

-(void)xyz{
        [self performSelectorInBackground:@selector(xyz) withObject:nil];
    }

- (void)viewDidLoad  {
   [self performSelector:@selector(xyz) withObject:nil afterDelay:0.3];
 }
like image 44
Sunny Shah Avatar answered Jan 29 '26 08:01

Sunny Shah



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!