を保持するUITableView
があります。ここで、 に aを追加したいと思い ます。しかし、これはうまくいきません。self.viewの作品...UITableViewCell
UIImageView
UILongGestureRecognizer
UIImageView
UILongGestureRecognizer
UILongGestureRecognizer
で動作する を実装する方法UIImageView
はUITableViewCell
?
TableViewController.h
@interface MagTableViewController : UITableViewController <UIGestureRecognizerDelegate>
@property (strong, nonatomic) UILongPressGestureRecognizer *longPress;
@property (strong, nonatomic) NSMutableArray *tableContent;
@end
TableViewController.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
}