Custom UiTableViewCell中的Multi Touch问题

时间:2011-08-22 07:09:45

标签: objective-c uitableview ios4 uitouch

static NSString *cellIdentifier = @"Cell";
AssignmentTableCell *cell = (AssignmentTableCell *) [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(cell == nil) {
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"AssignmentTableCell" owner:self options:Nil];
    cell = [nib objectAtIndex:0];
}

这是我自定义Cell初始化的代码。我正在检测自定义单元格的uitouch,然后我推动视图控制器而不是使用UItableView的DidSelected事件。但我面临的问题是

我一次可以选择2行,这不是我的意图,导致应用程序崩溃。我试图禁用多点触控,但没有用。他们仍然一直选择2个细胞。

任何帮助将不胜感激。

编辑1:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    imgBg.image = [UIImage imageNamed:@"rowSelected.png"];
    [[self delegate] touchStarted:tag];
}

-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
    imgBg.image = [UIImage imageNamed:@"7CustomCellBackground.png"];
    [[self delegate] touchEnded:tag];
}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    //imgBg.image = [UIImage imageNamed:@"7CustomCellBackground.png"];
    [[self delegate] rowTocuchedFromClicked:tag];
}

以下是细胞的接触方法。

1 个答案:

答案 0 :(得分:1)

您可以添加一些关于如何检测细胞触摸的代码吗?此外,您看到多个选择的原因是因为您没有取消选择所选单元格。做类似的事情 -

-(void) tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath)indexPath
{
    [tableView deselectRowAtIndexPath: indexPath animated: YES];
    //your other stuff
}

崩溃的原因是其他原因,只有在粘贴控制台日志后才能确定。

HTH,

阿克沙伊