3

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.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Vizllx
  • 9,135
  • 1
  • 41
  • 79

4 Answers4

9

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

    {

    }
Gajendra Rawat
  • 3,673
  • 2
  • 19
  • 36
2

Something like this

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

- (void)viewDidLoad  {
   [self performSelector:@selector(xyz) withObject:nil afterDelay:0.3];
 }
Sunny Shah
  • 12,990
  • 9
  • 50
  • 86
1

Use NSTimer

NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:3.0f target:self selector:@selector(xyz) userInfo:nil repeats:YES];
Himanshu Joshi
  • 3,391
  • 1
  • 19
  • 32
1

You should use NSTimer as mentioned by @mokujin. Please visit https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSTimer_Class/Reference/NSTimer.html

Pushparaj
  • 415
  • 8
  • 21