2016-02-26 56 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。但沒有運氣。 –

相關問題