Chen Wei Chen Wei - 4 months ago 12
Objective-C Question

iOS continuous action

The basic scenario is to request data from server once some

that represented by tags(
) has been edited by user. The general solution is to add events to observe those tags. Once any tag has been removed, a new http request could be submitted & then comes problem. For example, if user continuous deleted two tags, the original solution would submit two request continuously. It's definitely irrational as the first request is redundant.

So, is there any idea to regard those continuous action as a single operation?


Em, the solution here I found was NSTimer. By using that, I could set an auto-executed method which observing a count down value. Once that value count to zero, some actions could be trigged. If user continuously changed those tags, that count down value would be initialized repeatedly.

    timer = [NSTimer scheduledTimerWithTimeInterval:0.4f target:self selector:@selector(updateCounter:) userInfo:nil repeats:YES];


- (void)updateCounter:(NSTimer *)theTimer {
if(timeLeft > 0 ){
    //trigger update
    [timer invalidate];
    timer = nil;