0
UIButton * newButton = [UIButton buttonWithType:UIButtonTypeCustom];
newButton.imageObject= someImage;
UIImage * imagePut  = someImage.imageBlob;
imagePut = [imagePut roundedCornerImage:20 borderSize:0];
[newButton setImage:imagePut forState:UIControlStateNormal];

newButton.frame= CGRectMake(column * self.distanceBetweenButton +marginBetweenButtons, row *self.distanceBetweenButton+marginBetweenButtons, self.sizeOfButtons, self.sizeOfButtons);
newButton.backgroundColor = [UIColor clearColor];
PO(@(newButton.userInteractionEnabled));
newButton.userInteractionEnabled=YES;
[newButton addTarget:self action:@selector(someImageGotPressed) forControlEvents:UIControlEventTouchUpInside];
PO(@([newButton allControlEvents]));
PO(newButton.allTargets);
[self.collectionOfButton addObject:newButton];

简单的按钮。问题是 someImageGotPressed 从未被调用过。

newButton 当然默认有 userInteractionEnabled。但是, someImageGotPressed 仍然没有被调用。

目标是一个 UITableViewCell。我关闭了该 uiTableViewCell 的 userinteractionenabled,因为我希望人们与按钮进行交互。

我把它重新打开,它的工作原理。

然而,有些事情让我感到困惑。addTarget 中的目标可以是任何正确的。它甚至不必是 UIView 或 UIViewController。那么,为什么目标的 userInteractionEnabled 很重要呢?

这是因为 UITableViewCell 是按钮的超级视图,而关闭视图的 userInteractionEnabled 将在所有超级视图或类似的东西中关闭它?

4

1 回答 1

1

当您将超级视图的userInteractionEnabled( UITableViewCell) 设置为 NO 时,也会导致忽略对其子视图的所有触摸事件。

于 2012-10-30T07:56:22.160 回答