UIButton embedded in view which is then embedded in UIstackview not working

I have a UIButton of which I have a touchUpInside IBAoutlet function call, and it is embedded inside a view, which is then embedded inside a stackview. I have User Interaction enabled for all three of of the stackview, the view and the button. However, the touchUpInside function is not called when I click the button. Does anyone know if this has a solution?
Answered by Claude31 in 662164022
I tested and ran into the same problem.

In the stack, I added:
  • the button in the view : does not react to touch

  • a button directly in stack: it reacts to touch.

I have tried many of solutions proposed here, but yet to no avail:
https://stackoverflow.com/questions/39167337/unresponsive-uibutton-in-subview-added-to-uistackview

I looked at the view hierarchy and there is no view above the button…
Maybe the problem is in the size constraints for all elements, but I was not yet able to find out.

I'll continue to search.

EDIT
It finally worked, when setting size constraints on the view !
That is apparently due to the way StackView handles it own layout. Even though the view appears correct in IB (but in view debugger it is effectively zero size, but the button is there !), internally in Stack, it was considered zero size.

Here the configuration:
StackView
Axis Vertical
Alignement Leading
Distribution Fill
View: scale to Fill
User Interaction Enabled
Constraints : set position and size

UIView
Mode Scale to Fill
User interaction enabled
Constraints : set size THE CAUSE OF THE PROBLEM ! DOES NOT WORK WITHOUT THIS

Button
User interaction enabled of course
constraints : set position

Thanks to report here and close the thread if it works.

Good luck.

Accepted Answer
I tested and ran into the same problem.

In the stack, I added:
  • the button in the view : does not react to touch

  • a button directly in stack: it reacts to touch.

I have tried many of solutions proposed here, but yet to no avail:
https://stackoverflow.com/questions/39167337/unresponsive-uibutton-in-subview-added-to-uistackview

I looked at the view hierarchy and there is no view above the button…
Maybe the problem is in the size constraints for all elements, but I was not yet able to find out.

I'll continue to search.

EDIT
It finally worked, when setting size constraints on the view !
That is apparently due to the way StackView handles it own layout. Even though the view appears correct in IB (but in view debugger it is effectively zero size, but the button is there !), internally in Stack, it was considered zero size.

Here the configuration:
StackView
Axis Vertical
Alignement Leading
Distribution Fill
View: scale to Fill
User Interaction Enabled
Constraints : set position and size

UIView
Mode Scale to Fill
User interaction enabled
Constraints : set size THE CAUSE OF THE PROBLEM ! DOES NOT WORK WITHOUT THIS

Button
User interaction enabled of course
constraints : set position

Thanks to report here and close the thread if it works.

Good luck.

UIButton embedded in view which is then embedded in UIstackview not working
 
 
Q