【发布时间】:2013-07-12 22:41:10
【问题描述】:
我有一个 uitableview,它在点击单元格时实现弹出框 (PopoverView),然后弹出框将在屏幕上的任何其他点击时消失。问题是,如果用户要双击或重复点击单元格,它将导致显示多个弹出视图实例,然后应用程序将崩溃。我正在寻找一种方法来禁用双击单元格和/ 或一般的UITableView 或者有没有办法延迟对UITableViewCell 的任何想法?
我已经尝试过this,但它不适用于我的情况。 另一种方法是检查 PopoverView 是否已经存在,如果存在则不允许另一个实例化。我尝试了this 和this,但都不适用于我的情况。
这是我在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 方法中的内容包装在一个 if 语句中,该语句检查一个 BOOL,当视图返回时您将重置该 BOOL
-
您的评论也非常有帮助,谢谢。
-
很高兴来到这里并感谢您的反馈。
标签: iphone cocoa-touch uitableview