禁用uitableviewcell上的多个水龙头 [英] Disable multiple taps on uitableviewcell

查看:43
本文介绍了禁用uitableviewcell上的多个水龙头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个uitableview,当点击一个单元格时,它会实现一个弹出框( PopoverView )屏幕上的任何其他点击都会弹出窗口。问题是,如果用户要双击或重复单击单元格,则会导致显示多个popoverview实例,然后应用程序将崩溃。我正在寻找一种方法来禁用单元格上的双击并/或通常 UITableView 或是否有办法延迟对 UITableViewCell 任何想法的触摸?

I have a uitableview that implements a popover (PopoverView) when a cell is tapped and then the popover will dismiss on any other tap on the screen. The issue is that if a user would to double tap or tap repeatedly on the cell, it will cause multiple instances of popoverviews to display and then the application will crash.. I am looking for a way to either disable double tapping on the cell and/or the UITableView in general OR is there a way to delay touches on a UITableViewCell any ideas?

我已经尝试过,但在我的情况下不起作用。
另一种方法是检查PopoverView是否已经存在,如果不存在,则不允许其他实例化。我尝试了 this ,但两者在我的情况下均不起作用。

I already tried this but it does not work in my case. Another approach would to be to check if PopoverView is already present, if so then don't allow another one to instantiate. I tried this and this and both do not work in my case.

这是我的代码,我在 didSelectRowAtIndexpath 上调用弹出视图:

Here is my code where I call the 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];
}

解决方案

在接口类中:

 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;
}


推荐答案

将弹出窗口附加到属性在那个观点上。清除时,将其清除(通过委托方法)。在 didSelectRowAtIndexPath 中,如果没有关闭第一个弹出窗口,则不要创建另一个弹出窗口。

Attach the popover to a property on that view. Clear that when it is dismissed (via delegate method). In didSelectRowAtIndexPath don't create another popover if the first has not been dismissed.

这篇关于禁用uitableviewcell上的多个水龙头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆