UIStackView addArrangedSubview function reorders arrangedSubviews when providing view that is already in arrangedSubviews array

Originator:miikro
Number:rdar://FB8015604 Date Originated:15.07.2020
Status:Open Resolved:
Product:UIKit Product Version:
Classification: Reproducible:
 
Let’s say I have UIStackView instance where arrangedSubviews are [X, Y]. When I call addArrangedSubview(X) arrangedSubviews will be following array: [Y, X] which means that order of subviews has been altered.

According to Apple docs (https://developer.apple.com/documentation/uikit/uistackview/1616227-addarrangedsubview)
"This method automatically adds the provided view as a subview of the stack view, if it is not already. If the view is already a subview, this operation does not alter the subview ordering."

code:

import UIKit

let stackView = UIStackView()
stackView.axis = .horizontal

let textField = UITextField()
let button = UIButton()

stackView.addArrangedSubview(textField) // [UITextField]
stackView.addArrangedSubview(button) // [UITextField, UIButton]
stackView.addArrangedSubview(textField) // [UIButton, UITextField]

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!