链接两个(或更多)UISegmented控件

问题描述 投票:0回答:1

我正在尝试从第一个分段控件中获取答案,然后自动选择第二个(以及更多)分段控件的答案(如果所选答案为'否',则为自动)。因此,“ Question1”分段控制(是,否,不适用),如果选择“否”,则对“ Question2”(以及Q3,Q4等)分段控制做出回答,即“ N / A”。我可以让它单独在Question1上工作,即按“ No”,但在Question1上更改为“ N / A”,但我希望它保留Question1为“ No”,然后将Question2等更改为“ N / A”。我尝试将“发送方”更改为“ Question2”,但这不起作用。

    @IBOutlet weak var Queston2: UISegmentedControl! //Will need to add same for Q3 etc

    @IBAction func Question1(_ sender: UISegmentedControl) {

        if sender.selectedSegmentIndex == 0 {
        //Do stuff
        }

        else if sender.selectedSegmentIndex == 1 {

            sender.selectedSegmentIndex = 2                  // Change button to 'N/A', works for this question, but i want it to change Question2, not Question1.

     @IBAction func Question2(_ sender: UISegmentedControl) { // generally repeats as Question1 above.

我已经找到了一些类似的答案,但是它们似乎比我想的要复杂得多。非常感谢您的期待。

ios swift uisegmentedcontrol
1个回答
0
投票

您通常是对的,但是我只想在Q1的答案为“否”时执行此操作,然后将Q2向前更改为“ N / A”。

© www.soinside.com 2019 - 2024. All rights reserved.