The basic scenario is to request data from server once some parameters that represented by tags(UIView) 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?

有帮助吗?

解决方案 2

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.

-(void)countDownTimer{
if(!timer){
    timer = [NSTimer scheduledTimerWithTimeInterval:0.4f target:self selector:@selector(updateCounter:) userInfo:nil repeats:YES];
}
 timeLeft=2;

}

- (void)updateCounter:(NSTimer *)theTimer {
if(timeLeft > 0 ){
    timeLeft--;
    NSLog(@"%d",timeLeft);
}
else{
    //trigger update
    //balabala
    [timer invalidate];
    timer = nil;
}

}

其他提示

I need more information about the connection between the server and the purpose of the procedure. But if you control the backend, you can pass a json with as much information as you need. if you don't control the backend, it depends if the web service used supports.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top