我正在使用MVVM-Coordinator模式进行项目。 我必须有2个屏幕,ProductList和Product Detail。在产品详细信息中,我有相似的产品,当选择相似的产品时,我希望在产品详细信息屏幕中显示新数据。
在ProductListCoordinator中显示产品详细信息:
func navigateToProductDetail(productID: Int, api: APIClient) {
let pDetailCoordinator = PDetailCoordinator(navigationController: navigationController)
let pDetailViewModel = PDetailViewModel(dependencies: PDetailViewModel.Dependencies(productID: productID,
api: api,
coordinator: pDetailCoordinator))
let pDetailViewController = UIStoryboard.pDetail.pDetailViewController
pDetailViewController.viewModel = pDetailViewModel
vodDetailViewController.modalPresentationStyle = .custom
vodDetailViewController.modalTransitionStyle = .coverVertical
self.navigationController.present(vodDetailViewController, animated: true, completion: nil)
}
在ProductDetailCoordinator中显示类似产品:
func navigateToSimilarProductDetail(productID: Int, api: APIClient) {
let pDetailCoordinator = PDetailCoordinator(navigationController: navigationController)
let pDetailViewModel = PDetailViewModel(dependencies: PDetailViewModel.Dependencies(productID: productID,
api: api,
coordinator: pDetailCoordinator))
let pDetailViewController = UIStoryboard.pDetail.pDetailViewController
pDetailViewController.viewModel = pDetailViewModel
vodDetailViewController.modalPresentationStyle = .custom
vodDetailViewController.modalTransitionStyle = .coverVertical
vodDetailViewController.modalPresentationStyle = .overCurrentContext
let currentViewcontroller = self.navigationController.visibleViewController
if currentViewcontroller is VodDetailViewController {
currentViewcontroller!.present(vodDetailViewController, animated: true, completion: nil)
}
}
我的问题是,ProductList呈现ProductDetail,ProductDetail呈现ProductDetail,但是第三次我想呈现一个新的ProductDetail页面时,我得到了:
警告:尝试演示已演示的内容
而且,self.navigationController.popViewController(animated: true)
对任何PDetailViewController都不起作用。