【发布时间】:2015-09-29 07:36:57
【问题描述】:
简介:-
在我的项目中,我在自定义 TableViewCell(videoTableViewCell.h) 中包含的 UIImageView 上使用 UITapGestureRecognizer。我添加了一个 tapGesture 和 longPressGesture 来执行一些操作。看到这个Question
我启用了 userInteraction.than 我收到了来自 cell.image2_2 和 cell.image1_1 的回复。
问题:- 但 cell.image1_2 没有在 tapGesture 或 longPressGesture 上回复。
注意: image1_2 和 image2_2 在一个单元格中(重用标识符 two),而 image1_1 在另一个单元格中(重用标识符 one)
宏
RADIOUS 16.0
TITLE_COLOR [UIColor colorWithRed:102.0/255.0 green:255.0/255.0 blue:0/255.0 alpha:1]
videoViewController.m
-->UITableView 数据源方法
-(void)tableView:(UITableView *)tableView willDisplayCell:(videoTableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
UITapGestureRecognizer* tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(Action:)];
tapGesture.numberOfTapsRequired = 1;
UILongPressGestureRecognizer* longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(handleLongPress:)];
if(indexPath.row%2 == 0){//cell with two boxes
NSArray* array = [newArray objectAtIndex:indexPath.row];
if(array.count > 1){//WHEN CONATAINS TWO OBJECTS in Array
NSString* string = [array objectAtIndex:0];
if(string){
cell.image1_2.hidden = NO;
}else{
cell.image1_2.hidden = YES;
}
[cell.image1_2 setImage:[self getThumbNailByName:string]];
NSString*tag = [NSString stringWithFormat:@"%ld%ld",indexPath.row,(long)0];
cell.image1_2.tag = [tag integerValue];
[cell.image1_2 addGestureRecognizer:tapGesture];
if(selectionEnabled){
if([selectedItems containsObject:[NSNumber numberWithInteger:[tag integerValue]]]){
cell.image1_2.layer.borderWidth = 1.0;
cell.image1_2.layer.borderColor = TITLE_COLOR.CGColor;
}else{
cell.image1_2.layer.borderColor = [UIColor clearColor].CGColor;
cell.image1_2.layer.borderWidth = 0;
}
}else{
[cell.image1_2 addGestureRecognizer:longPress];
}
string = [array objectAtIndex:1];
if(string){
cell.image2_2.hidden = NO;
}else{
cell.image2_2.hidden = YES;
}
[cell.image2_2 setImage:[self getThumbNailByName:string]];
tag = [NSString stringWithFormat:@"%ld%ld",indexPath.row,(long)1];
cell.image2_2.tag = [tag integerValue];
[cell.image2_2 addGestureRecognizer:tapGesture];
if(selectionEnabled){
if([selectedItems containsObject:[NSNumber numberWithInteger:[tag integerValue]]]){
cell.image2_2.layer.borderWidth = 1.0;
cell.image2_2.layer.borderColor = TITLE_COLOR.CGColor;
}else{
cell.image2_2.layer.borderColor = [UIColor clearColor].CGColor;
cell.image2_2.layer.borderWidth = 0;
}
}else{
[cell.image2_2 addGestureRecognizer:longPress];
}
}else{// WHEN CONATAINS ONLY ONE OBJECT in Array
NSString* string = [array objectAtIndex:0];
if(string){
cell.image1_2.hidden = NO;
}else{
cell.image1_2.hidden = YES;
}
NSString*tag = [NSString stringWithFormat:@"%ld%ld",indexPath.row,(long)0];
cell.image1_2.tag = [tag integerValue];
[cell.image1_2 addGestureRecognizer:tapGesture];
cell.image2_2.hidden = YES;
if(selectionEnabled){
if([selectedItems containsObject:[NSNumber numberWithInteger:[tag integerValue]]]){
cell.image1_2.layer.borderWidth = 1.0;
cell.image1_2.layer.borderColor = TITLE_COLOR.CGColor;
}else{
cell.image1_2.layer.borderColor = [UIColor clearColor].CGColor;
cell.image1_2.layer.borderWidth = 0;
}
}else{
[cell.image1_2 addGestureRecognizer:longPress];
}
}
}else{//cell with one box
NSString* string = [[newArray objectAtIndex:indexPath.row] objectAtIndex:0];
if(string){
cell.image1_1.hidden = NO;
}else{
cell.image1_1.hidden = YES;
}
[cell.image1_1 setImage:[self getThumbNailByName:string]];
NSString*tag = [NSString stringWithFormat:@"%ld%ld",indexPath.row,(long)0];
cell.image1_1.tag = [tag integerValue];
[cell.image1_1 addGestureRecognizer:tapGesture];
if(selectionEnabled){
if([selectedItems containsObject:[NSNumber numberWithInteger:[tag integerValue]]]){
cell.image1_1.layer.borderWidth = 1.0;
cell.image1_1.layer.borderColor = TITLE_COLOR.CGColor;
}else{
cell.image1_1.layer.borderColor = [UIColor clearColor].CGColor;
cell.image1_1.layer.borderWidth = 0;
}
}else{
[cell.image1_1 addGestureRecognizer:longPress];
}
}
}
videoTableViewCell.m
- (void)awakeFromNib
{
// Initialization code
[image1_1 setUserInteractionEnabled:YES];
[image1_2 setUserInteractionEnabled:YES];
[image2_2 setUserInteractionEnabled:YES];
if([self.reuseIdentifier isEqualToString:@"one"]){
image1_1.layer.cornerRadius = RADIOUS;
image1_1.clipsToBounds = YES;
}else{
//Two Album Cell'cell2'
image1_2.layer.cornerRadius = RADIOUS;
image1_2.clipsToBounds = YES;
image2_2.layer.cornerRadius = RADIOUS;
image2_2.clipsToBounds = YES;
}
}
如果有人需要更多信息,请问我。
顺便说一下,谢谢关注。
【问题讨论】:
标签: ios objective-c iphone uitableview uiimageview