Search code examples
iosuiscrollviewios11uistackviewios12

iOS 12, issue with UIStackView


I have used UIStackView to create chips which can be removed by the button of delete. It was working fine with iOS 11 as shown below

Result in iOS 11

But, I am facing an issue of overlapping of Tags in iOS 12 when I tried to remove the chip. The View removed from the list but it remained somewhere and that's why it was displaying like below:

Result in iOS 12

I tried to investigate and found that Views which I removed were still there in the stack but in the array of arrangedSubviews count was 0

enter image description here

Can anyone help me in finding the solution for this? or is it the known issue of iOS 12?


Solution

  • The documentation for -[UIStackView removeArrangedSubview:] advises you to remove the formerly arranged view from the UIStackView by invoking removeFromSuperview after removeArrangedSubview:.

    In iOS 11 and lower, the view's position was moved off screen when you called -[UIStackView removeArrangedSubview:] and did not removing the formerly arranged view from the UIStackView. Because it was moved away, I personally never noticed the documentation that it should be removed from the superview as well.

    In iOS 12, the view is no longer moved offscreen. This enforces that you should follow the documentation's advise to remove the view from the stack view.

    https://developer.apple.com/documentation/uikit/uistackview/1616235-removearrangedsubview