I have two contradicting sources in regards to IBOutletCollection with NSArray. First says that the order that you link things from interface to outlet collection is significant, and it will always be the same in outlet collection. E.g. if we link first text field first to collection, element number 0 will be that field, etc.
But another source tells me that this is wrong and actually Outlet collection is randomized and there is absolutely no guarantee in the order of things. So element number zero can be any text field, and not just the first connected in interface.
"iOS 6 Programming - exploring iOS SDK" is the first source and Stanford course on iTunes is the second source. Who is right?
Simply assign the order of controls by tag
and on load reorder them.
@IBOutlet var btnCollection: [UIButton]! { didSet { btnCollection.sort { $0.tag < $1.tag } } }
override func viewDidLoad() { super.viewDidLoad() btnCollection = btnCollection.sorted { $0.tag < $1.tag } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With