Disable multiple taps on uitableviewcell

I have a uitableview that implements a popover ( PopoverView ) when a cell is being listened, and then the popover is rejected on any other click on the screen. The problem is that if the user briefly clicks or clicks on a cell twice, this will cause several instances of popoverviews to appear, and then the application will work. I'm looking for a way to disable double-clicking on a cell and / or UITableView in general OR is there a way to defer touches on UITableViewCell any ideas?

I already tried this one , but in my case it does not work. Another approach would be to check if a PopoverView is present, if so, and then not allow the creation of another instance. I tried this and this , and both of them do not work in my case.

Here is my code where I call popover view on didSelectRowAtIndexpath :

 - (void)tableView:(UITableView *)TableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [TableView cellForRowAtIndexPath:indexPath]; sti = [[SelectedTeamsInfo alloc] init]; MyLeagueStandings *info = [fetchedResultsController objectAtIndexPath:indexPath]; [sti getAllScheduleForTeam:info.urlforteam]; NSString *title = info.teamname; // If title length is greater then 32 truncate it to fit. if (title.length > 32) { title = [info.teamname substringToIndex:29]; title = [title stringByAppendingString:@"..."]; } [PopoverView showPopoverAtPoint:cell.center inView:self.view withTitle:title withContentView:sti.view delegate:self]; } 

Decision

In the interface class:

  BOOL PopoverYN; 

In the implementation class:

 - (void)tableView:(UITableView *)TableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // If the popover is not available then display it else do nothing since one is already displayed. if (PopoverYN == NO) { PopoverYN = YES; UITableViewCell *cell = [TableView cellForRowAtIndexPath:indexPath]; sti = [[SelectedTeamsInfo alloc] init]; MyLeagueStandings *info = [fetchedResultsController objectAtIndexPath:indexPath]; [sti getAllScheduleForTeam:info.urlforteam]; NSString *title = info.teamname; // If title length is greater then 32 truncate it to fit. if (title.length > 32) { title = [info.teamname substringToIndex:29]; title = [title stringByAppendingString:@"..."]; } [PopoverView showPopoverAtPoint:cell.center inView:self.view withTitle:title withContentView:sti.view delegate:self]; } } #pragma mark - popover methods. - (void)popoverViewDidDismiss:(PopoverView *)popoverView; { PopoverYN = NO; } 
+4
source share
2 answers

Attach a popover to a property in this view. Clear it when it is rejected (via the delegate method). In didSelectRowAtIndexPath do not create another popover unless the first has been fired.

0
source

I have one more solution. Hope this helps someone. If you want to detect a second tap and consume it, then that’s all, it worked for me. I loaded the web view on one tap, if there are two consecutive branches, the error received the NSURLErrorCancelled event and caused a white flash screen on the webview . I could handle this at the web presentation level, but I, although I have to kill the root issue.

 NSTimer *avoidDoubleTapTimer; - (void) onTimer { NSLog(@"Timer out"); avoidDoubleTapTimer = nil; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if(avoidDoubleTapTimer == nil) { avoidDoubleTapTimer = [NSTimer scheduledTimerWithTimeInterval:0.3 target:self selector:@selector(onTimer) userInfo:nil repeats:NO]; } else { NSLog(@"Double Tap Detected"); return; } // do you stuff on single tap } 
+3
source

Source: https://habr.com/ru/post/1491213/


All Articles