我有一个UITableView
with UITableViewCell
which 持有UIImageView
的。现在我想 UILongGestureRecognizer
在UIImageView
's 中添加一个。但这不起作用。UILongGestureRecognizer
关于self.view的作品...
如何实现UILongGestureRecognizer
它在UIImageView
's 中的UITableViewCell
's 上工作?
表视图控制器.h
@interface MagTableViewController : UITableViewController <UIGestureRecognizerDelegate>
@property (strong, nonatomic) UILongPressGestureRecognizer *longPress;
@property (strong, nonatomic) NSMutableArray *tableContent;
@end
表视图控制器.m
- (void)viewDidLoad
{
self.longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressed:)];
self.longPress.minimumPressDuration = 0.2;
self.longPress.numberOfTouchesRequired = 1;
//[self.view addGestureRecognizer:self.longPress]; // This works!
}
// [...]
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
UIImageView *imvLeft = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 100)];
[imvLeft setImageWithURL:[NSURL URLWithString:self.tableContent[@"url"]]];
imvLeft.userInteractionEnabled = YES; // added soryngod's hint, but does not
// solve the problem, as only the last row of 5 is enabled...
[imvLeft addGestureRecognizer:self.longPress]; // does not work...
[cell.contentView addSubview:imvLeft];
return cell;
}
-(void)longPressed:(UILongPressGestureRecognizer *)recognizer {
// do stuff
}