Ios controls the trigger frequency of button click events

Source: Internet
Author: User

Ios controls the trigger frequency of button click events

This problem is often encountered in projects:

When a button is clicked, a corresponding click event is triggered. For example, a network request is sent to the server or a pop-up dialog box is displayed.

However, if a user clicks more frequently, the click event will be triggered continuously to confuse the UI.

My solution to this problem is to set a Boolean value.

(1) Click events that interact with the server: Determine the bool value when you click; Set it once before sending the request; change the bool value after the server receives a response.

(2) For serverless interactive click events: determine when you click, set before the dialog box is executed, and set the latency of 0.25 seconds after the dialog box is completed.

Directly Add code

 

 

....

@ Property (nonatomic, assign) BOOL hasLiked;

....

 

 

-(Void) viewWillAppear :( BOOL) animated

{

[Super viewWillAppear: animated];

Self. hasLiked = YES;

}


 

-(Void) btnClick :( UIButton *) button

{

_ Weak VSwiperViewController * weakSelf = self;

If (button. tag = 500 ){

NSInteger userAccountScore = [[VUserInfoEntityManager sharedManager] getPrivateUserInfo]. score;

 

If (userAccountScore <_ fpzGiftprice & self. hasLiked = YES) {// click hasLiked.

Self. hasLiked = NO; // set it before executing the dialog box

 

[WeakSelf showNotEnoughCoinsAlertView];

Dispatch_after (dispatch_time (DISPATCH_TIME_NOW, (int64_t) (0.25 * NSEC_PER_SEC), dispatch_get_main_queue (), ^ {

WeakSelf. hasLiked = YES; // After the pop-up box is complete, the latency is set to 0.25 seconds.

});

 

}

}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.