我有 UIScrollView,其中包含许多以下订阅 View Controller 。每个订阅 View Controller 都包含容器 View Controller 。
目标是在右侧的 4 个 Views Controllers 之间进行简单导航。
导航逻辑:
- 在 viewDidLoad 上显示 Container 中的第一个或第二个 View Controller
- 当用户按下 View Controller 上的按钮时,在 Container 中显示第三个 View Controller
我尝试使用 Segues 但这没有用。实例化VC的方式 订阅 View Controller 不是个好主意。
最佳答案
使用此代码切换容器 View View ...
@IBOutlet weak var container: UIView!
var currentViewController:UIViewController?
//put the view did load method here.
@IBAction func buttonPressed() {
//the storyboard file that the view is in.
let storyboard:UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
// the container view you want to switch to.
self.currentViewController = storyboard.instantiateViewControllerWithIdentifier("containerViewStoryboardID") as? UIViewController
//switch the container view.
self.addChildViewController(self.currentViewController!)
self.container.addSubview(self.currentViewController!.view)
self.currentViewController!.didMoveToParentViewController(self)
}
关于ios - 4 个 View Controller 之间的简单自定义导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31210799/