我有自定义UITableViewCell与UIView“backgroundView”添加到TableViewCell contentView。现在,UIImageView“sharedImage”被添加为“backgroundView”的子视图。UIButton不会在自定义UITableviewCell中响应
这里我添加一个UIButton“downloadButton”作为子视图到“sharedImage”。
我有一个“downloadButton”的选择器方法。但不幸的是,这个动作方法并没有被UIButton调用。
我已经尝试更改UIControlEventTypes,尝试更改UserInteractionEnabled,bringSubViewToFront选项,但没有运气。
这是代码。
/*Add the background view to the Tableview Cell*/
UIView *backGroundView = [[UIView alloc] init];
backGroundView.frame = CGRectMake(mainViewFrameWidth - widthOfTheBackGroundView - 10.0 , 3.0, widthOfTheBackGroundView, heightOfTheBackGroundView);
backGroundView.backgroundColor = [[UIColor hs_globalTint] colorWithAlphaComponent:0.2];
backGroundView.layer.cornerRadius = 3.0;
backGroundView.tag = 101;
[sendingImageTableViewCell.contentView addSubview:backGroundView];
NSString *imagePath = [NSString stringWithFormat:@"%@/%@",[self.appDelegateInstance getDocumentsPath],mFileInfo.thumbnailPath];
UIImageView *sharedImage = [[UIImageView alloc] init];
sharedImage.image = [self getSquareImageByCropping:[UIImage imageWithContentsOfFile:imagePath] withOrientation:UIImageOrientationUp];
sharedImage.contentMode = UIViewContentModeScaleAspectFit;
sharedImage.tag = 102;
[backGroundView addSubview:sharedImage];
sharedImage.frame = CGRectMake(5.0, 5.0, widthOfTheImageView, heightOfTheImageView);
UIButton *uploadButton = [UIButton buttonWithType:UIButtonTypeCustom];
uploadButton.frame = CGRectMake(0.0, 0.0, 30.0, 30.0);
uploadButton.selected = YES;
uploadButton.enabled = YES;
uploadButton.tag = indexPathOfTheImageCell.row;
uploadButton.backgroundColor = [UIColor clearColor];
[uploadButton addTarget:self action:@selector(onClickOfUploadButton:) forControlEvents:UIControlEventTouchUpInside];
[backGroundView addSubview:uploadButton];
阅读有关响应者链文档,但不能解决问题。任何人都可以让我知道如果我在这里错了吗?
你需要'UIControlEventTouchDown'?如果你需要点击动作应该使用'UIControlEventTouchUpInside' – jose920405