从 ContainerView 内部切换到另一个 ContainerView
Switch to another ContainerView from inside a ContainerView
我用 Xcode 和 Swift 制作了一个 iOS 应用。
一个 ViewController 包含两个 ContainerView。用户可以使用 SegmentedControl 在它们之间切换。
但是,如何在没有 SegmentedControl 的情况下切换到另一个 ContainerView,例如用一个按钮?
其实我有这个代码:
let vc : AnyObject! = self.storyboard!.instantiateViewControllerWithIdentifier("login")
self.showViewController(vc as! UIViewController, sender: vc)
这将打开另一个 ContainerView,但作为单个 VC,不在父 ViewController 内。
我该怎么做才能到达父级中显示的另一个 ContainerView VC?
您还必须设置 ContainerViews
viewControllers
中的 IBoutlets
才能使用 uibuttons
操作分别调用它们。
assign same class to both parentViewcontroller and containerView using identity inspector see image.
connect IBOutlet as well like parentViewController see image
现在可以使用 uibutton
操作从 class 访问。
遍历父视图控制器的子项
parentViewController.childViewControllers.indexOf(self)
你得到了索引,意味着你可以得到控制器然后你可以显示它
我用 Xcode 和 Swift 制作了一个 iOS 应用。
一个 ViewController 包含两个 ContainerView。用户可以使用 SegmentedControl 在它们之间切换。
但是,如何在没有 SegmentedControl 的情况下切换到另一个 ContainerView,例如用一个按钮?
其实我有这个代码:
let vc : AnyObject! = self.storyboard!.instantiateViewControllerWithIdentifier("login")
self.showViewController(vc as! UIViewController, sender: vc)
这将打开另一个 ContainerView,但作为单个 VC,不在父 ViewController 内。
我该怎么做才能到达父级中显示的另一个 ContainerView VC?
您还必须设置 ContainerViews
viewControllers
中的 IBoutlets
才能使用 uibuttons
操作分别调用它们。
assign same class to both parentViewcontroller and containerView using identity inspector see image.
connect IBOutlet as well like parentViewController see image
现在可以使用 uibutton
操作从 class 访问。
遍历父视图控制器的子项
parentViewController.childViewControllers.indexOf(self)
你得到了索引,意味着你可以得到控制器然后你可以显示它