ios - How to check how many times UIButton pressed in One Second -
i developing simple apple watch demo. in want check how many times uibutton
pressing in 1 second.
give me hint question.
here code implemented:
- (void)awakewithcontext:(id)context { [super awakewithcontext:context]; [btnbell setbackgroundimage:[uiimage imagenamed:@"bell.png"]]; [self performselector:@selector(checkcount) withobject:nil afterdelay:1.0]; nslog(@"%@ awakewithcontext", self); self.counter = 0; } - (void)willactivate { // method called when watch view controller visible user nslog(@"%@ activate", self); } - (void)diddeactivate { // method called when watch view controller no longer visible nslog(@"%@ did deactivate", self); } #pragma mark - button actions - (ibaction)savecounter { //send count parent application self.counter++; nsstring *counterstring = [nsstring stringwithformat:@"%d", self.counter]; nsdictionary *applicationdata = [[nsdictionary alloc] initwithobjects:@[counterstring] forkeys:@[@"countervalue"]]; //handle reciever in app delegate of parent app [wkinterfacecontroller openparentapplication:applicationdata reply:^(nsdictionary *replyinfo, nserror *error) { [self showsavenotificationlabel]; }]; } #pragma mark - helper methods -(void)showsavenotificationlabel { nsstring *soundfilepath = [[nsbundle mainbundle] pathforresource: @"beep1" oftype: @"mp3"]; nsurl *fileurl = [[nsurl alloc] initfileurlwithpath: soundfilepath]; myaudioplayer = [[avaudioplayer alloc] initwithcontentsofurl:fileurl error:nil]; myaudioplayer.volume = 0.1; [myaudioplayer play]; } -(void)checkcount { nslog(@"button tap clicked : %d times", self.counter); self.counter = 0; }
feel free ask regarding code. , give me suggestion.
global variable :
int buttontapcounts;
viewdidload method :
[self performselector:@selector(checkcount) withobject:nil afterdelay:1.0];
method uibutton event :
-(ibaction)tapbuttonclicked:(id)sender { buttontapcounts ++; }
check counter after 1 second :
-(void)checkcount { nslog(@"button tap clicked : %d times", buttontapcounts); // resetting button count buttontapcounts = 0; }
Comments
Post a Comment