IPhone UIButton doesn't respond in a UIScrollV

2019-05-31 15:38发布

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?

3条回答
做自己的国王
2楼-- · 2019-05-31 16:19

try [btn becomeFirstResponder];

查看更多
一纸荒年 Trace。
3楼-- · 2019-05-31 16:21

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!

查看更多
来,给爷笑一个
4楼-- · 2019-05-31 16:29

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

查看更多
登录 后发表回答