我有一个 uitableview,它在点击单元格时实现弹出框(PopoverView),然后弹出框将在屏幕上的任何其他点击时关闭。问题是,如果用户要双击或重复点击单元格,它将导致显示多个弹出视图实例,然后应用程序将崩溃。我正在寻找一种方法来禁用双击单元格和/或UITableView
一般来说,或者有没有办法延迟UITableViewCell
任何想法的接触?
我已经尝试过了,但在我的情况下它不起作用。另一种方法是检查 PopoverView 是否已经存在,如果存在则不允许另一个实例化。我试过这个和这个,但在我的情况下都不起作用。
这是我在其中调用弹出视图的代码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;
}