Executing methods one after another with pauses between executing

后端 未结 2 1793
孤独总比滥情好
孤独总比滥情好 2021-01-03 12:08

Newbie obj-c question. I am writing a simple iPad presentation not for Appstore. My task is to implement few methods executed one after another with little pauses between th

2条回答
  •  死守一世寂寞
    2021-01-03 12:27

    You could use the single timer and write a switch statement around the methods you want to execute in the order you want to execute them. e.g.

    int turn = 0;
    NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(runmethod) userInfo:nil repeats:NO];
    

    then in run method

    switch(turn)
    {
      case 0:
            // do method 1 stuff
            ++turn;
            break;
      case 1:
            // do method 2 stuff
            ++turn;
            break;
        .
        .
        .
    }
    
    NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(runmethod) userInfo:nil repeats:NO];
    

提交回复
热议问题