From the UIStackView Class Reference
In removeArrangedSubview:
To prevent the view from appearing on screen after calling the stack’s removeArrangedSubview: method, explicitly remove the view from the subviews array by calling the view’s removeFromSuperview method.
In arrangedSubview:
Whenever an arranged view’s removeFromSuperview method is called, the stack view removes the view from its arrangedSubview array
From these, it seems that calling just removeFromSuperview is enough to remove a subview and I've been using it like that without problems. I also confirmed the behavior by logging the count of the arrangedSubviews array when removeFromSuperview is called.
A lot of tutorials and comments here on S/O however, say to call both. Is there a reason for this? Or do people just do it because the documentation says so?
removeArrangedSubview
without knowing I was supposed to also callremoveFromSuperview
, and it was indeed clearing the view fromarrangedSubviews
but the view was still appearing insubviews
causing all kinds of confusing breakage. Adding theremoveFromSuperview
call (once I saw this question!) resolved it. – FabulousremoveFromSuperview
. I'm only callingremoveFromSuperview
without any issues. – Pulsimeter