我已經使用自定義單元格實現了tableview。單元格上有圖像視圖,並且我添加了手勢識別器。但是當我點擊imageview來觸發某個事件時,它會使用數字作爲我滾動表格視圖的方法。假設我滾動tableview 5次然後它imageview也觸發該方法5次。在tableview滾動過程中將事件添加到imageview
這是代碼:
{
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;
一次通過(細胞==零)阻止 – iSpark
@murali我檢查已經寫我們的代碼檢查。但是通過將代碼放在塊中,它會一次又一次地顯示相同的圖像。 –
請將您的代碼放入您的問題中,而不是鏈接到pastebin。這次我已經爲你修好了。 –