我已经用自定义单元格实现了表格视图。单元格上有图像视图,我在其中添加了手势识别器。但是,当我单击 imageview 以触发某些事件时,当我滚动表格视图时,它会转到带有数字的方法。假设我滚动了 tableview 5 次,那么它 imageview 也会触发该方法 5 次。
这是代码:
{
if (cell == nil)
{
cell = [[[CustomTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.frame = CGRectMake(0.0, 0.0, 320.0, 200.0);
}
cell.accessoryType = UITableViewCellAccessoryNone;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.backgroundColor=[UIColor redColor];
[cell.image1 setTag:indexPath.row*2];
[cell.image2 setTag:indexPath.row*2+1];
NSString *pathimage1 =[[aroundmearray objectAtIndex:indexPath.row*2]objectForKey:@"image"];
NSString *filePath1 = [NSString stringWithFormat:@"%@",pathimage1];
NSString *pathimage2=[[aroundmearray objectAtIndex:indexPath.row*2+1]objectForKey:@"image"];
NSString *filePath2 = [NSString stringWithFormat:@"%@",pathimage2];
UITapGestureRecognizer *tap1 =
[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handlefirstTap:)];
tap1.delegate=self;
tap1.numberOfTapsRequired=1;
[cell.image1 addGestureRecognizer:tap1];
[tap1 release];
UITapGestureRecognizer *tap2 =
[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handlesecondTap:)];
tap2.delegate=self;
tap2.numberOfTapsRequired=1;
[cell.image2 addGestureRecognizer:tap2];
[tap2 release];
[cell.image1 setImageWithURL:[NSURL URLWithString:filePath1]placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
[cell.image2 setImageWithURL:[NSURL URLWithString:filePath2]placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
}
return cell;