Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using coordinator to embed a controllers into subviews #11

Open
chaaarly opened this issue Jan 18, 2019 · 0 comments
Open

Using coordinator to embed a controllers into subviews #11

chaaarly opened this issue Jan 18, 2019 · 0 comments

Comments

@chaaarly
Copy link

Hello,

i started using coordinators in my app. It's ok to present controllers throught navigation controllers, tabbar controllers or modally. But i wonder how to use it to embed a view controller in a subview. My app has a 2 panels controller and each panel contains its own sub view controller (with coordinator).

I tried this way :

`

class MainCoordinator: BaseCoordinator {

private let navigationController: UINavigationController

init(navigationController: UINavigationController) {
    self.navigationController = navigationController
}

override func start() -> Observable<Void> {
    let viewController = MainViewController.initFromStoryboard(name: "Main")

    let viewModel = MainViewModel()
    viewController.viewModel = viewModel

    self.navigationController.pushViewController(viewController, animated: true)
    
    self.presentFirstPanel(intoContainerView: viewController.firstPanelViewContainer)

    return Observable.never()
}

private func presentFirstPanel(intoContainerView containerView:UIView) {
    let firstPanelCoordinator = FirstPanelCoordinator(withContainerView: containerView)
    _ = self.coordinate(to: organizationPanelCoordinator)
}

}

class FirstPanelCoordinator: BaseCoordinator {

private let containerView:UIView
init(withContainerView containerView:UIView) {
    self.containerView = containerView
}

override func start() -> Observable<Void> {
    
    let viewController = FirstPanelViewController.initFromStoryboard(name: "OrganizationPanel")
    
    let viewModel = FirstPanelViewModel()
    viewController.viewModel = viewModel
    
    self.containerView.addSubview(viewController.view)
    viewController.view.frame = self.containerView.bounds
    viewController.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
    
    return Observable.never()
}

}`

... but when i add my first panel to the container view, the container view is nil so it crash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant