Boudz78 Boudz78 - 7 months ago 89
Swift Question

Using Segmented Control to perform segues

I am Trying to Perform Segues with Segmented Control Buttons.
//Segmented Control

@IBOutlet weak var SegmentControl: UISegmentedControl!
@IBAction func Segment(sender: UISegmentedControl) {
switch SegmentControl.selectedSegmentIndex {
case 0:
shouldPerformSegueWithIdentifier("hello1", sender: self)
case 1:
shouldPerformSegueWithIdentifier("hello2", sender: self)
default:
break;
}
}


Although The App Build Well, When i Click one of Segments the App doesn't perform the segue.Im kind of new to swift , I'm not sure if this works,however its worth the try. Thank You.

Answer

It should be

performSegueWithIdentifier("hello1", sender: self)

instead of

shouldPerformSegueWithIdentifier("hello1", sender: self)

So your code should like this:

@IBOutlet weak var SegmentControl: UISegmentedControl!
@IBAction func Segment(sender: UISegmentedControl) {
switch SegmentControl.selectedSegmentIndex {
case 0:
    performSegueWithIdentifier("hello1", sender: self)
case 1:
    performSegueWithIdentifier("hello2", sender: self)
default:
    break;
}
}
Comments