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];
Simple button. The problem is someImageGotPressed is never called.
The newButton of course have userInteractionEnabled by default. However, someImageGotPressed is still not called.
The target is a UITableViewCell. I turned off the userinteractionenabled for that uiTableViewCell because I expect people to interact with the button.
I turned that back to on and it works.
However, something puzzles me. The target in addTarget can be anything right. It doesn’t even have to be a UIView or UIViewController. So why the hell the userInteractionEnabled for target matters at all?
Is this because UITableViewCell is the superview of the button and turning off userInteractionEnabled of a view will turn that off in all it’s superView or that sort of thing?
when you set the super view’s
userInteractionEnabled(UITableViewCell) to NO, that will cause ignoring all the touches event to its subviews too.