Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my "touch up inside" event for my UIButton not being called?

I've made plenty of buttons and I can't figure out why this one won't work.

My hierarchy is set up like this:

View -> Scroll View -> Subview -> Button 

There's a lot of other items in this subview and every one of them works when touched. In the interface builder I can see that the "Touch Up Inside" event is bound to my method

- (IBAction)favoritesButtonDepressed:(id)sender  

However, when I click the button, that method never executes and my breakpoint is subsequently never hit.

I noticed that even when I hold down my press on the button, the label doesn't change color (even though shows touch on highlight is enabled), but yet my other button on the view does.

User Interaction is enabled on the button as well as everything up the hierarchy.

In order for my items in the sub view to receive touch events, I made my scroll view look like the 4th answer in this post.

like image 610
Architekt Avatar asked Jan 15 '14 03:01

Architekt


People also ask

How can I check if UIButton is pressed?

You can use the following code. class ViewController: UIViewController { var gameTimer: Timer! @IBAction func btnClick(_ sender: Any) { let button = UIButton() if (button. isSelected) { print(" Not Selected"); } else { print(" Selected"); } } override func viewDidLoad() { super.

How do I turn off highlighting in UIButton?

make your button Type - "Custom" and Uncheck - Highlighted Adjust image and you are done.


2 Answers

Aha, I got it. It turns out the subview which contained the button (along with the other controls) had a height of 740 and the button was at a Y of 781. Moving the button up fixed the issue. Since everything was displaying correctly, I didn't think to check the subview's height.

like image 184
Architekt Avatar answered Sep 20 '22 04:09

Architekt


Make sure that your button is placed inside superView's bounds,
If a button is placed outside superView's bounds, the button will not clickable,
because of the implement of the hitTest function

like image 39
Shawn Wang Avatar answered Sep 21 '22 04:09

Shawn Wang