Ways to prevent buttons from being clicked multiple times in iOS

Source: Internet
Author: User

Principle: The concept of autolock in C + + is realized by using the principle of local variable lifetime limited to the current function or the current code block, which is actually the concept of smart pointers.

The setenable of the button at the time of creation of the local variable is no, and setenable is yes at the end of the function without a block. If there is a block, you need to adjust the Blockit function, in fact, there is nothing to do, Just to let LLVM know that this variable will be released at the end of the block.

Header file

@interface d1autodisablebutton:nsobject{    uibutton* Sender;} Call the interface, declare a temporary variable, note that it cannot be global or self-member, and if you want to cross a function call, pass it as a parameter + (ID) Objectwithbutton: (uibutton*) obj;//do something in the block, Otherwise the variable will be released before the block executes.-(void) Blockit; @end

Realize

@implementation d1autodisablebutton-(ID) init{    [Super Doesnotrecognizeselector:_cmd];    return nil;} + (ID) Objectwithbutton: (uibutton*) obj{    d1autodisablebutton* lockobj = [[D1autodisablebutton alloc]initWithParam : obj];    return lockobj;} -(ID) Initwithparam: (uibutton*) obj{    sender = obj;    [Sender setenabled:no];//    NSLog (@ "Auto disable:%x", sender);    return self;} -(void) dealloc{    [sender Setenabled:yes];    NSLog (@ "Auto enable:%x", sender);} -(void) blockit{    //nslog (@ "block call it");} @end

Using the Arc

Ways to prevent buttons from being clicked multiple times in iOS

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.