ios 无法识别 uiimagview 点击手势
ios uiimagview tap gesture not recognised
tableview 单元格内的图像视图点击手势不起作用。
以下是代码。
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:
(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] ;
CGRect frame1 = CGRectMake(5, 0, 320, 30);
UILabel *label = [[UILabel alloc] initWithFrame:frame1];
label.text = @"READ THIS";
label.font = [UIFont fontWithName:@"Helvetica" size:15];
cell.backgroundColor = [UIColor colorWithRed:231.0f/255.0f green:234.0f/255.0f blue:235.0f/255.0f alpha:1.0];
UIImageView *downImage =[[UIImageView alloc] initWithFrame:CGRectMake(270,0,35,35)];
downImage.image=[UIImage imageNamed:@"downimg.png"];
downImage.userInteractionEnabled = YES;
downImage.tag = indexPath.row;
UITapGestureRecognizer *tapped = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(myFunction:)];
tapped.numberOfTapsRequired = 1;
[downImage addGestureRecognizer:tapped];
[label addSubview:downImage];
[cell.contentView addSubview:label];
对于要在其中添加 UIImageView
作为子视图的 UILabel
,请将 UserInteractionEnabled
设置为 YES
属性 userInteractionEnabled
默认情况下也对 UILabel
禁用。
tableview 单元格内的图像视图点击手势不起作用。
以下是代码。
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:
(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] ;
CGRect frame1 = CGRectMake(5, 0, 320, 30);
UILabel *label = [[UILabel alloc] initWithFrame:frame1];
label.text = @"READ THIS";
label.font = [UIFont fontWithName:@"Helvetica" size:15];
cell.backgroundColor = [UIColor colorWithRed:231.0f/255.0f green:234.0f/255.0f blue:235.0f/255.0f alpha:1.0];
UIImageView *downImage =[[UIImageView alloc] initWithFrame:CGRectMake(270,0,35,35)];
downImage.image=[UIImage imageNamed:@"downimg.png"];
downImage.userInteractionEnabled = YES;
downImage.tag = indexPath.row;
UITapGestureRecognizer *tapped = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(myFunction:)];
tapped.numberOfTapsRequired = 1;
[downImage addGestureRecognizer:tapped];
[label addSubview:downImage];
[cell.contentView addSubview:label];
对于要在其中添加 UIImageView
作为子视图的 UILabel
,请将 UserInteractionEnabled
设置为 YES
属性 userInteractionEnabled
默认情况下也对 UILabel
禁用。