我有一个 uitableview 实现了弹出窗口(弹出视图 https://github.com/runway20/PopoverView)当点击某个单元格时,弹出窗口将在屏幕上的任何其他点击时消失。问题是,如果用户双击或重复点击单元格,则会导致显示多个弹出视图实例,然后应用程序将崩溃。我正在寻找一种方法来禁用单元格上的双击并/或者UITableView
一般来说,或者有没有办法延迟触摸UITableViewCell
有任何想法吗?
我已经尝试过了this https://stackoverflow.com/questions/1031254/how-can-i-detect-a-double-tap-on-a-certain-cell-in-uitableview但它不适用于我的情况。
另一种方法是检查 PopoverView 是否已经存在,如果存在则不允许实例化另一个。我试过this https://stackoverflow.com/questions/2777438/how-to-tell-if-uiviewcontrollers-view-is-visible and this https://stackoverflow.com/questions/5503187/uiview-how-to-find-out-if-a-view-is-already-exists两者都不适用于我的情况。
这是我的代码,我在其中调用弹出窗口视图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];
}
SOLUTION:
在接口类中:
BOOL PopoverYN;
在实现类中:
- (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;
}
我还有一种解决方案。希望这会对某人有所帮助。如果您想检测第二次点击并使用它,那么就是这样,这对我有用。我正在单击加载网页视图,如果连续两次点击,则会出现错误NSURLErrorCancelled
事件并导致白色闪屏webview
。我可以在 webview 级别处理它,但我认为我应该从根本上解决这个问题。
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
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)