2016-02-26 51 views
-1

我有自定义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]; 

阅读有关响应者链文档,但不能解决问题。任何人都可以让我知道如果我在这里错了吗?

+0

你需要'UIControlEventTouchDown'?如果你需要点击动作应该使用'UIControlEventTouchUpInside' – jose920405

回答

1

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

+0

我已经启用按钮YES。但没有运气。 –

相关问题