1

I'm trying to make an iOS app. As part of the app, I want a UIScrollView to scroll every X seconds. I believe that I need to use NSTimer. Is this correct?

Moshe
  • 57,511
  • 78
  • 272
  • 425

4 Answers4

3

Yes. You can use NSTimer for this:

float interval = 2.5f; //whatever interval you want
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:interval target:someTarget selector:@selector(someSelector:) userInfo:nil repeats:YES];
Jacob Relkin
  • 161,348
  • 33
  • 346
  • 320
2

Yes. You can use NSTimer to perform either a delayed event or a periodic event. There is a good post on using NSTimer here.

Community
  • 1
  • 1
Error 454
  • 7,255
  • 2
  • 33
  • 48
1

Yes.

NSTimer* theTimer = [NSTimer scheduledTimerWithTimeInterval:X
                                                     target:someController
                                                   selector:@selector(scrollThatView)
                                                   userInfo:nil
                                                    repeats:YES];
kennytm
  • 510,854
  • 105
  • 1,084
  • 1,005
0

You don’t need to use an NSTimer—there are other ways to do it—but yes, an NSTimer will allow you to do so.

Jeff Kelley
  • 19,021
  • 6
  • 70
  • 80
  • Really, what else can be used? – Moshe Oct 28 '10 at 18:15
  • Well, you could run code in a background thread that polled the time every run, you could run code in a background thread that sleeps between invocations, etc. An `NSTimer` is probably your best bet, though. – Jeff Kelley Oct 28 '10 at 19:37