通过代码打开ViewController

时间:2017-05-16 19:09:14

标签: ios swift

我目前正在开发一款iOS应用程序,它通过BLE与Arduino通信,与多个ViewControllers一起使用,这些ViewControllers都是通过Storyboard设置的。视图通过TabBarController进行管理。此时我使用额外的Tab来连接/断开设备。

但是在没有设备的应用程序没用之后,我想要弹出ViewController(管理连接任务)。我已经读过我应该使用Segues,但我真的不知道如何正确调用它们,我不想在每个TabViewController中调用它们。

1 个答案:

答案 0 :(得分:1)

Segues是你应该使用的,但我建议学习故事板如何工作。 Ray Wenderlich将是一个很好的资源,可以帮助您入门。 Segues可以通过代码使用,也可以直接在故事板中使用。

你的问题是通用的方式来直接回答,因为我写了大约1000个单词来降低基础。

为了简单起见:

  • performSegue(withIdentifier: "segueIdentifier", sender: nil)

  • presentViewController(mainViewController, animated: true, completion: nil)

  • navigationController?.pushViewController(mainViewController, animated: true)