UIButton在自定义UITableviewCell中没有响应

时间:2016-02-26 19:17:59

标签: ios objective-c uibutton uitableview

我有自定义UITableViewCell,并在TableViewCell contentView中添加了UIView“backgroundView”。现在,UIImageView“sharedImage”被添加为“backgroundView”的子视图。

这里我将UIButton“downloadButton”作为子视图添加到“sharedImage”。

我有一个“downloadButton”的选择器方法。但不幸的是,UIButton没有调用action方法。

我尝试过更改UIControlEventTypes,尝试更改UserInteractionEnabled,带上SubViewToFront选项,但没有运气。

这是代码。

        /*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];

了解响应者链文档,但无法解决问题。如果我在这里出错了,有谁可以告诉我?

1 个答案:

答案 0 :(得分:1)

您使用uploadButton.enabled = NO;配置了您的UIButton您可以将其更改为YES。 根据Apple的GUI指南,UIButton的最小高度/宽度应为44.0f,否则用户可能无法点击它。