“This is the 7th day of my participation in the Gwen Challenge in November. Check out the details: The Last Gwen Challenge in 2021.”

The cause of

In one development, a button was written on the view, but there was always no response event when I clicked on it. I was very upset. Although the final solution was very simple and I looked like a fool, it was a problem until the problem was found, so I recorded the process of finding the bug this time. Look for bugs in the simplest place, don’t think there can’t be a problem or something like that, then the bug is probably in the simplest place you despise.

1. Check userInterfaractionEnabled

Check whether the parent view userInterfaractionEnabled open, no userInterfaractionEnabled is open control interaction properties of events, if this attribute is not open, so how to debug Too waste. The first step is to check this.

2. Check the view hierarchy

Check that the control is located on the superview, If the child view is taller than the parent view, and the nearest control on the child view is a button, then clicking on the button will not trigger an event. In this case, it is difficult to detect the bug from logic, but only from the UI.

3. Check whether the control is overwritten

If the button has a transparent view covering it, it will not respond. This is easy to check both logically and in the UI

4. frame

Check the frame of the button. If the actual frame and the displayed UI are not consistent, then the portion of the button that is beyond the frame will not respond to the event.

5. touchBegin

Check by adding a touchBegin method to the superview. Is the superview interaction event closed?

6. Response chain

You can look at the responder chain, which layer the event went to, which layer was responded to, and what caused it not to go to the next layer. NSLog(@”%@”,button.responder); NSLog(@”%@”,button.responder.responder); , etc.

7. Other

Like not adding click events, etc…

conclusion

If I still can’t find the bug of the response through the above method, I can do nothing about it. If you have a better method, please let me know in the comment section. If I still can’t find it, I can only pack it and go home.