Vizllx
Vizllx

Reputation: 9246

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.

Upvotes: 3

Views: 8813

Answers (4)

Gajendra Rawat
Gajendra Rawat

Reputation: 3663

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

    {

    }

Upvotes: 9

Himanshu Joshi
Himanshu Joshi

Reputation: 3399

Use NSTimer

NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:3.0f target:self selector:@selector(xyz) userInfo:nil repeats:YES];

Upvotes: 1

Sunny Shah
Sunny Shah

Reputation: 13020

Something like this

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

- (void)viewDidLoad  {
   [self performSelector:@selector(xyz) withObject:nil afterDelay:0.3];
 }

Upvotes: 2

Related Questions