如何从UISegmentControl创建IBAction?

时间:2016-04-12 09:07:06

标签: ios swift uisegmentedcontrol ibaction

我在项目中处理UISegmentControl。我能够创造出口&在{&1;}的帮助下,UISegmentControl的出口集合下降。但无法创建段控制的IBAction。 我想我错过了很小的事情。任何想法我现在该怎么办? 为了更加清晰,您可以参考此屏幕截图。enter image description here

3 个答案:

答案 0 :(得分:2)

这与按钮操作相同唯一的区别是选择TouchUpInside或其他按钮事件,您应该使用“ ValueChanged

UISegmentControll将响应值更改操作

答案 1 :(得分:1)

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

答案 2 :(得分:1)

您需要单击右上角的assitant Navigator打开实施文件,然后在弹出对话框屏幕的@implementation指令后将段控制拖动到实现文件。

enter image description here

相关问题