基本上,它是這樣的問題: How to detect touches on UIImageView of UITableViewCell object in the UITableViewCellStyleSubtitle style如何在Swift中檢測UITableViewCell的UIImageView上的觸摸?
但我必須在Swift中做到這一點。我不能在Obejctive-C中編程。
cell.imageView.userInteractionEnabled = YES;
cell.imageView.tag = indexPath.row;
UITapGestureRecognizer *tapped = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(myFunction:)];
tapped.numberOfTapsRequired = 1;
[cell.imageView addGestureRecognizer:tapped];
[tapped release];
-(void)myFunction :(id) sender
{
UITapGestureRecognizer *gesture = (UITapGestureRecognizer *) sender;
NSLog(@"Tag = %d", gesture.view.tag);
}
有人可以幫助我移植此代碼嗎? 。:(
漂亮!最後擺脫了我的UIImage定製UIButton :)很多感謝隊友,在iOS 11/Swift 4中也能很好地工作。 – Maziyar