I am rendering the view based on the enum . For case .loaded , I am showing the self.showDetails which is a view controller and it showing the when I select the cell form table view and it working fine.
case .loaded(let details):
self.showDetails(details)
Here is the code for it ..
private func showDetails(_ Details: Details) {
let displayViewController = DetailsDisplayViewController(movieDetails: Details)
addChild(displayViewController)
displayViewController.view.frame = view.bounds
displayViewController.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
currentViewController?.willMove(toParent: nil)
transition(
from: currentViewController,
to: displayViewController,
duration: 0.25,
options: [.transitionCrossDissolve],
animations: nil
) { (_) in
self.currentViewController.removeFromParent()
self.currentViewController = displayViewController
self.currentViewController.didMove(toParent: self)
}
}
But now I have to add another collection view at the bottom of the details view. I have created another enum for it as well.
case .pageLoaded(let page):
self.showSimiliarDetails(page)
Here is the function for it .. same code just reuse it.
private func showSimiliarDetails(_ similiarDetails: Page<Details>) {
let smiliarViewController = SmiliarController(viewModel: viewModel)
addChild(smiliarViewController)
smiliarViewController.view.frame = view.bounds
smiliarViewController.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
currentViewController?.willMove(toParent: nil)
transition(
from: currentViewController,
to: smiliarViewController,
duration: 0.25,
options: [.transitionCrossDissolve],
animations: nil
) { (_) in
self.currentViewController.removeFromParent()
self.currentViewController = smiliarViewController
self.currentViewController.didMove(toParent: self)
}
}
I have configured the collection view cell smiliarViewController with data source. I am trying to display both view controller when table view cell is clicked. form table view cell is passing the id and which is get the similar record into collection view .
I have tried to pass it as array and also use + operator like this way ..
let arrayVc = viewController + similiarVC
self.navigationController?.pushViewController(arrayVc, animated: true)
it gives error .. **Binary operator '+' cannot be applied to operands of type **
the second approach was passing like array ..
let arrayVc = [viewController , similiarVC]
self.navigationController?.pushViewController(arrayVc, animated: true)
but it showing this error ..
Cannot convert value of type '[UIViewController]' to expected argument type 'UIViewController'
Here is the didselcte code ..
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let value = viewModel.state.value[indexPath.row]
let viewModel = ViewModel(value: value, apiManager: APIManager())
let viewController = DetailsViewController(viewModel: viewModel)
let similiarVC = SmiliarViewController(viewModel: viewModel)
let arrayVc = [viewController , similiarVC]
self.navigationController?.pushViewController(arrayVc, animated: true)
}
is there any alternative to do it ?
If understand correctly, you want to push both controllers onto the view stack? If so, then you should just be able to call
pushViewController(...)twice: