Если 2 контроллера, которые вы хотите показать, это
class Act1ViewController: UIViewController {
//your code...
}
class Act2ViewController: UIViewController {
//your code...
}
Вам просто нужно поставить корпус переключателя на buttonName's
title
и представить соответствующий контроллер act1
или act2
. Создайте act1
и act2
, используя storyboard
.
@IBAction func buttonPressed(_ sender: UIButton) {
switch sender.titleLabel?.text {
case "cheer up":
if let act1 = self.storyboard?.instantiateViewController(withIdentifier: "Act1ViewController") as? Act1ViewController {
self.present(act1, animated: true, completion: nil)
}
case "yay":
if let act2 = self.storyboard?.instantiateViewController(withIdentifier: "Act2ViewController") as? Act2ViewController {
self.present(act2, animated: true, completion: nil)
}
default:
break
}
}
}
Не забудьте установить Act1ViewController
и Act2ViewController
как storyboardID
соответствующего контроллеры в storyboard
.