使用 Swift 在故事板之间切换
Switch Between Storyboards Using Swift
我的 Xcode 项目中的故事板变得太大,拖慢了我的计算机速度。如何以编程方式(或手动使用故事板)使用按钮从当前故事板中的一个视图前进到新故事板上的视图?
半新 Xcode 所以越简单越好。谢谢!
您可以通过编程方式执行此操作:
Swift 3+
let storyboard = UIStoryboard(name: "StoryboardName", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "ViewControllerID") as UIViewController
present(vc, animated: true, completion: nil)
年长
let storyboard = UIStoryboard(name: "myStoryboardName", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("nextViewController") as UIViewController
presentViewController(vc, animated: true, completion: nil)
在排序中你可以这样做:
presentViewController( UIStoryboard(name: "myStoryboardName", bundle: nil).instantiateViewControllerWithIdentifier("nextViewController") as UIViewController, animated: true, completion: nil)
并且不要忘记为您的 nextViewController 提供 ID。
有关更多信息,请参阅 THIS。
Swift3 解法:
present( UIStoryboard(name: "CreateOrder", bundle: nil).instantiateViewController(withIdentifier: "firstOrderViewController") as UIViewController, animated: true, completion: nil)
0 行代码
使用界面生成器
- 将故事板参考添加到源故事板
- Control-Drag 从
UIButton
到那个 故事板参考
- 在故事板参考占位符的属性检查器中,指定目标故事板和可选目标
UIViewController
和 Bundle.
的目的地 Reference ID
完整图片
我的 Xcode 项目中的故事板变得太大,拖慢了我的计算机速度。如何以编程方式(或手动使用故事板)使用按钮从当前故事板中的一个视图前进到新故事板上的视图?
半新 Xcode 所以越简单越好。谢谢!
您可以通过编程方式执行此操作:
Swift 3+
let storyboard = UIStoryboard(name: "StoryboardName", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "ViewControllerID") as UIViewController
present(vc, animated: true, completion: nil)
年长
let storyboard = UIStoryboard(name: "myStoryboardName", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("nextViewController") as UIViewController
presentViewController(vc, animated: true, completion: nil)
在排序中你可以这样做:
presentViewController( UIStoryboard(name: "myStoryboardName", bundle: nil).instantiateViewControllerWithIdentifier("nextViewController") as UIViewController, animated: true, completion: nil)
并且不要忘记为您的 nextViewController 提供 ID。
有关更多信息,请参阅 THIS。
Swift3 解法:
present( UIStoryboard(name: "CreateOrder", bundle: nil).instantiateViewController(withIdentifier: "firstOrderViewController") as UIViewController, animated: true, completion: nil)
0 行代码
使用界面生成器
- 将故事板参考添加到源故事板
- Control-Drag 从
UIButton
到那个 故事板参考
- 在故事板参考占位符的属性检查器中,指定目标故事板和可选目标
UIViewController
和 Bundle.
的目的地 Reference ID