根据 运行 次选择的 UISegmented 控件隐藏标签

Hide a label based on selection of UISegmented controls at run time

我在 UISegmented 控件中有两个段。我想要的是根据 运行 时间段的选择隐藏标签。

例如:

if SegControl.selectedSegmentIndex == 1 {
    descriptStar.isHidden = true
    PriceStar.isHidden = true                               
}

我正在尝试这个,但它不起作用。请帮忙。

谢谢

我以前有一个来自 segmentedControl 的出口,但没有 @IBAction 方法。我创建了一个连接到分段控件的 @IBAction 方法,并在该函数中插入了隐藏标签的代码,它起作用了。