我有自定义 UITableViewCell,我对 UITableViewCell 进行了子类化:
MyCustomCell.h
MyCustomCell:UITableViewCell
然后我还有这个自定义单元格的 xib 文件,一切正常,我可以显示所有信息,以及我在单元格上添加的图像,但是我想在用户触摸 uiimageview 时检测到触摸,所以我试过了这样:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"MasterView";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[MasterViewCell alloc] init];
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"MasterViewCustomCellImage" owner:self options:nil];
cell = (MasterViewCell *)[nib objectAtIndex:0];
//NSLog(@"Nuova Cella");
}
[self configureCell:cell atIndexPath:indexPath];
return cell;
}
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
NSManagedObject *managedObject = [self.fetchedResultsController objectAtIndexPath:indexPath];
UIImageView *thumbnailImage = (UIImageView *)[cell viewWithTag:1007];
[thumbnailImage setImage:[managedObject valueForKey:@"myImage"]];
if (thumbnailImage) {
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(detectTouchImage)];
[longPress setMinimumPressDuration:1.0];
[thumbnailImage setUserInteractionEnabled:YES];
[thumbnailImage addGestureRecognizer:longPress];
}
}
-(void)detectTouchImage
{
NSLog(@"Image Pressed");
}
但我不明白为什么不工作,如果它输入thumbnailImage,但没有检测到图像上的任何手势......任何人都可以帮助我吗?我已经在 ios 5 和 ios 6 上尝试过,但不工作...