Reputation: 1191
Is it possible to set a sort order for a UIStackView
? For example, I want to sort it by time. Each subview has a time
property which is just an Int
.
I know you can sort a UITableView
by sorting the array and then refreshing the table but UIStackView
doesn't have delegates and data sources like that so I don't know how to go about this. It just seems to go by the order you add the subviews in which makes it challenging to add a view in the middle without removing everything first.
Upvotes: 2
Views: 2927
Reputation: 2409
You can remove all arrangedSubviews and add or insert them again in you own order. Make sure this subviews is not hidden, because stackView sort them to head of arrangedSubviews array
Upvotes: 3
Reputation: 7756
Maybe read the documentation?
The stack view manages the layout of all the views in its
arrangedSubviews
property. These views are arranged along the stack view’s axis, based on their order in thearrangedSubviews
array.
Upvotes: 2