I'm trying to disable the bottom segment control if the user clicks Diesel. The problem is I can't connect two IBAction
s to each other. Such as:
@IBAction func didSelect(_ control: UISegmentedControl) {
switch control.selectedSegmentIndex
{
case 0:
isPetrol = true
isDiesel = false
case 1:
isPetrol = false
isDiesel = true
default:
print ("break")
}
}
@IBACtion func didSecondSelect (_ control: UISegmentedControl) {
//something here that when case1 is clicked disables it
}
}
How can I disable it if the top case 1 is clicked?
You are mixing up IBAction
s and IBOutlet
s.
You should create an IBOutlet
that points to the second segmented control and change that from the first one's code.
@IBOutlet weak var secondSegmentedControl: UISegmentedControl!
@IBAction func didSelect(_ control: UISegmentedControl) {
[...]
secondSegmentedControl.isEnabled = control.selectedSegmentIndex == 0
}
For more information about working with IBOutlet
s, check out this question.