IPhone UIButton doesn't respond in a UIScrollV

2019-05-31 15:53发布

问题:

I'm an iPhone dev newbie, and I'm having a problem slightly similar to a few posts I read around here, but none of them seemed to help.

I have created a UIScrollView, with a UIView as its content (a subview). During runtime, the UIView is populated with labels and buttons. Everything looks fine, scrolling works perfectly, but the UIButtons never fire when pressed, no matter what I do. I've tried many combinations of properties suggested here, to the best of my understanding, but still nothing worked. I'm afraid I might have misunderstood something about the mechanism.

I should mention that everything is done in code (no IB).

Any suggestions?

回答1:

My bug (written in the comments of my question) was not setting the frame of the contentview that was the parent of all buttons. The result was strange - I could see the button subviews (which was why it took me a while to find the bug) but could not click on them. oops!



回答2:

This also may happen, when your custom UIView userInteractionEnabled is NO (default is NO).



回答3:

try [btn becomeFirstResponder];