我想在不使用导航 Controller 的情况下按下按钮时切换到新的 View Controller ,但我似乎无法做到这一点。我到处寻找答案,但我发现的一切要么在 objective-c 中,要么使用导航 Controller ,要么根本不工作。
func gunsoutButtonPressed(sender:UIButton!) {
print("yay\t")
//let encounterVC:AnyObject! = self.storyboard?.instantiateViewControllerWithIdentifier("ecounterViewController")
//self.showViewController(encounterVC as UIViewController, sender: encounterVC)
let encounterViewController = self.storyboard.instantiateViewControllerWithIdentifier("encounterViewController") as encounterViewController
self.pushViewController(encounterViewController, animated: true)
}
最佳答案
您必须连接您要使用的两个 ViewController。然后根据需要命名 segue,然后使用以下代码触发 segue(在 IBAction 或其他内容中)。它不完全以编程方式进行,但您可以以编程方式触发它们,这应该足够了。
performSegueWithIdentifier("mySegue", sender: nil)
查看 this video寻求支持。
希望这有帮助:)
关于ios - 在没有导航 Controller Swift 的情况下以编程方式更改 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29132511/