Reputation: 53
So I am wanting to keep track of which direction the user would like to cycle through. Hence I have a segmented control to select the direction.
Here is the code:
@IBOutlet weak var cycleSwitch: UISegmentedControl!
@IBAction func setCycleDirection(sender: AnyObject) {
switch cycleSwitch.selectedSegmentIndex
{
case 0:
cycleDirection = cycleSwitch.selectedSegmentIndex
case 1:
cycleDirection = cycleSwitch.selectedSegmentIndex
default:
break
}
println(cycleDirection)
}
but nothing gets printed. Even if I comment everything out and just have a println("Im in the action") does not log. I have also tried this as if statements e.g. cycleSwitch.selectedSegmentIndex == 0 etc. Neither works.
Any suggestions or thoughts as to why the values won't change?
Upvotes: 2
Views: 2413
Reputation: 951
A few things to check:
@IBAction
via its "Value Changed" action.
To do this, control+click your segmented control in your Storyboard and double-check to make sure "Value Changed" is wired to your View Controllersender:
argument to be a UISegmentedControl
instead of AnyObject
cycleSwitch
@IBOutlet
, reference sender
in your switch statement:switch sender.selectedSegmentIndex
{
case 0:
cycleDirection = sender.selectedSegmentIndex
case 1:
cycleDirection = sender.selectedSegmentIndex
default:
break
}
Upvotes: 5