Quantcast
Viewing all articles
Browse latest Browse all 11

Answer by guru for Prevent multiple Tap on the same UIButton

Disable isUserInteractionEnabled or disable the button not work some cases, if have background API calling in next controller, push process will work asynchronously.

After some work around i thought its better to go with the other way, i found Completion handler in Objective-C or Closure in Swift can be good here.

Here is the example which i used in Objective c:

 -(void)didSettingClick:(id) sender{    if (!isPushInProcess) {             isPushInProcess = YES;            SettingVC *settings = [[SettingVC alloc] initWithcomplition:^{               isPushInProcess = NO;            }];            [self.navigationController pushViewController:settings animated:YES];           }}

Here is method description:

dispatch_block_t pushComplition;-(instancetype) initWithcomplition:(dispatch_block_t)complition{    self = [super init];    if (self) {        pushComplition = complition;    }    return self;}

Inside viewDidAppear()

-(void)viewDidAppear:(BOOL)animated{    pushComplition();}

In swift using defer keyword is also can be good idea.

Hope It help!!!


Viewing all articles
Browse latest Browse all 11

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>