Repeating a method every few seconds in Objective C

10,844

The problem is that target is nil.

What this timer does is every 7 seconds it calls [nil foo], which does nothing.

If you want to call the method foo on the object that creates the timer, use target:self

Share:
10,844

Related videos on Youtube

Snowman
Author by

Snowman

Updated on June 12, 2022

Comments

  • Snowman
    Snowman almost 2 years

    I have a method -(void)foo that I want to call once in viewDidAppear, then I want it to repeat every n seconds, where n is some integer. How can I do this?

    I tried this, but it's not repeating:

    [NSTimer scheduledTimerWithTimeInterval:7.0 target:nil selector:@selector(foo) userInfo:nil repeats:YES];
    

Related