ios - 如何从 UISegmentedControl 创建 IBAction?

标签 ios swift uisegmentedcontrol ibaction

我在我的项目中处理UISegmentControl。我能够在拖放的帮助下创建 UISegmentControl 的 socket 和 socket 集合。但无法创建段控制的 IBAction。 我想我错过了非常小的东西。知道我现在应该如何进行吗? 为了更清楚,您可以引用此屏幕截图。 enter image description here

最佳答案

在你的 controller 中尝试这段代码:

@IBOutlet weak var segmentedControl: UISegmentedControl!
@IBAction func segmentedControl(sender: AnyObject) {

    if segmentedControl.selectedSegmentIndex == 1 {

        // Do something with the first button
    }
    else {
        // Do something with the second button, etc...
    }
}

然后将它从您的code拖到您的segmentedControl

关于ios - 如何从 UISegmentedControl 创建 IBAction?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36568548/

相关文章:

ios - 无法弄清楚如何将字符串编码为 Google Static Map API iOS 的 URL

ios - 将 fft 计算与 View Controller 分开

ios - 具有关联类型的协议(protocol)。如何避免在协议(protocol)的所有实现上手动分配类型

swift - Swift 5 中的引用赋值是原子的吗?

ios - 以编程方式更新 UISegmentControl 不会更新未选定段的字体颜色

ios - 使用 Swift 3 和 Realm 同步 Apple Watch 和 iPhone

ios - iOS7 上的 UISearchDisplayController

iphone - 如何检测 uisegmentedcontrol 上的触摸 - 即使在选定的段上?

ios - 我如何将 "pin" Sprite 转换为 Sprite Kit 中的其他 Sprite ?

ios - 谁能告诉我如何去除 CarbonKit 中的深灰色底部边框