S
S
Sergey Sulakov2016-06-02 10:07:03
Objective-C
Sergey Sulakov, 2016-06-02 10:07:03

Change numbers by interval in iOS app?

There is an application on iOS, in short, the essence is this:
a set of terms (numbers) is generated, the next digit appears every second and is accompanied by an audio file (voicing of this number), at the end the visitor needs to enter the total answer.
The problem arises in the following:
How to do it in the best way?
sleep(1) and NSThread are not suitable, because then it seems that the application is frozen and does not respond to the exit button, etc.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Egor Sh, 2016-06-02
@web-verzus-team

@interface MyViewController () {
    NSTimer *timer;
    int seconds;
    ...
} 
@property (weak, nonatomic) IBOutlet UILabel *timerLabel;
@end
...

- (void)viewDidLoad
{
    [super viewDidLoad];
    timer = [NSTimer scheduledTimerWithTimeInterval:1.0f  target:self selector:@selector(updateTimer:) userInfo:nil repeats:YES];
   seconds = 0;
}

- (void)updateTimer:(NSTimer *)theTimer {
   [functions playSound:[NSString stringWithFormat:@"%@",seconds] ofType:@"aac"];
   seconds++;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question