I'm starting to develop apps in Xcode 6 with swift. It's my first experience with programming. I'm developing an app that needs to have more than one user interface, and I want to switch between them with a segmented control. Can anybody tell me how to do it? Thanks
Asked
Active
Viewed 372 times
0
-
Have you considered using a `UITabBarController`? It's designed for switching between UIs. – rob mayoff Sep 29 '14 at 20:08
-
Oh, that's great, I didn't that it existed. Thank you for the tip – Gabriel Bitencourt Sep 30 '14 at 17:00
2 Answers
1
Here is an example from one of my projects with an IBAction from the UISegmentedControl using a switch statement for control flow. It was a calculator app. Don't worry about the specific logic. But you can see how to do what you asked. Use each case of the switch statement to segue to a different view.
@IBAction func dateSegmentedControl(sender: UISegmentedControl) {
oneDayArray = []
switch sender.selectedSegmentIndex
{
case 0:
segmentedControlCase = "All"
oneDayArray = historyGameData
self.historyViewTable.reloadData()
break
case 1:
segmentedControlCase = "+"
historyArray(historySign: segmentedControlCase)
case 2:
segmentedControlCase = "-"
historyArray(historySign: segmentedControlCase)
case 3:
segmentedControlCase = "x"
historyArray(historySign: segmentedControlCase)
case 4:
segmentedControlCase = "÷"
historyArray(historySign: segmentedControlCase)
default:
break;
}
}

Steve Rosenberg
- 19,348
- 7
- 46
- 53
0
Please find the below code snippet for creating the simple uisegmentedcontrol in ios
@IBOutlet weak var segmentedControl: UISegmentedControl!
@IBOutlet weak var textLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
textLabel.text = "First Segment Selected";
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func segmentedControlAction(sender: AnyObject) {
if(segmentedControl.selectedSegmentIndex == 0)
{
textLabel.text = "First Segment Selected";
}
else if(segmentedControl.selectedSegmentIndex == 1)
{
textLabel.text = "Second Segment Selected";
}
else if(segmentedControl.selectedSegmentIndex == 2)
{
textLabel.text = "Third Segment Selected";
}
}
if need detail explanation please refer the below link.
https://sourcefreeze.com/uisegmentedcontrol-example-using-swift-in-ios/

Bharathi Devarasu
- 7,759
- 2
- 18
- 23