Xcode Objective-C | iOS: delay function / NSTimer help?

前端 未结 7 2115
旧巷少年郎
旧巷少年郎 2021-02-01 15:32

So I\'m developing my first iOS application and I need help..

Simple program for now, I have about 9 buttons and when I press the first button, or any button, I just wan

7条回答
  •  轮回少年
    2021-02-01 15:50

    sleep doesn't work because the display can only be updated after your main thread returns to the system. NSTimer is the way to go. To do this, you need to implement methods which will be called by the timer to change the buttons. An example:

    - (void)button_circleBusy:(id)sender {
        firstButton.enabled = NO;
        // 60 milliseconds is .06 seconds
        [NSTimer scheduledTimerWithTimeInterval:.06 target:self selector:@selector(goToSecondButton:) userInfo:nil repeats:NO];
    }
    - (void)goToSecondButton:(id)sender {
        firstButton.enabled = YES;
        secondButton.enabled = NO;
        [NSTimer scheduledTimerWithTimeInterval:.06 target:self selector:@selector(goToThirdButton:) userInfo:nil repeats:NO];
    }
    ...
    

提交回复
热议问题