我有自定義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