Our discussion goes nowhere if you do not answer questions, precisely.
1. What is the result of
print("selectedButton", selectedButton)
print("therapistGenderMale.tag", therapistGenderMale.tag) // Idem for all others
Have you defined IBAction for the button ?
Can you show the code of the IBAction associated to the buttons (if any) ?
Have you checked that the connection of the buttons to their IBOutlet are valid ?
Could you post the crashlog (with the sigabrt message)
==> PLEASE answer those questions
2. I still don't understand how to make an array
Do you mean an array of UIButton ?
Did you follow the steps ?
To create an array of UIButton:
- create a button in IB
- control-drag to viewController, and select Outlet collection
- you get this declaration:
@IBOutlet var allButtons: [UIButton]!
- create a second button in IB
- control-drag from the IBOutlet declaration to this new button, it will be included in Outlet collection ([UIButton]
==> WHERE exactly do you have problem ?
3. what you mean when you say you will probably set this var when you prepare to segue to the view
The buttons are in a controller (let call it destVC)
You go there from initilalVC
What you want, is that a button in destVC is preselected when you show destVC
==> IS THAT what you want ?
If so, when you segue, you need to tell destVC which button to hilite ; hence, you need to pass a parameter with selectedButton.
4. To do this, you have to:
- know which is preselectedButton ; this is done in initialVC. You store this value in thePreselectedButton
- How it is done, depends on your app ; on which condition do you choose the preselected button ? As you don't show code, it is hard to say
- Probably, you should have code as:
if someCondition {
thePreselectedButton = 1
} else if someOtherCondition {
thePreselectedButton = 2
} else if yetAnotherCondition {
thePreselectedButton = 3
} else {
thePreselectedButton = 0 // No preselection
}
- in prepare, you write
destVC.selectedButton = thePreselectedButton
- in destVC, you have define a var (selectedButton) to receive the value
var selectedButton = 0
- in destVC, in viewDidLoad, you use the value to set the hilite of the selectedButton, by calling hiliteButtons()