如何多次推送相同的 ViewController ?
How can I push the same ViewController more than once?
我有一个列表,我想显示它 3 次(当我单击特定单元格时,从一个列表到另一个列表)。为此,我正在使用包含我的 ListView 的 XIB。我还设置了一个 NavigationController 来播放推送动画。
这就是我在 rootViewController 中调用 pushViewController 方法的方式。
case "Groupe" :
//this is OK since it's the first time I push the ViewController
service.getGroupe()
let vueGroupe = vueListe!
navigationController?.pushViewController(vueGroupe, animated: true)
vueListe.navigationItem.title = "Groupe View";
case "Categorie" :
//this is not
let vueCat = vueListe!
service.getCategorie(ids: elem!)
navigationController?.pushViewController(vueCat, animated: true)
vueListe.navigationItem.title = "Groupe View";
使用此代码我得到以下错误:
"Pushing the same view controller instance more than once is not supported"
如何多次推送同一个 ViewController?
您应该创建 UIViewController
对象的新实例并推送它。
因此,在您的代码中,它将类似于:
case "Groupe":
service.getGroupe()
let vueGroupe = VueListeViewController() // I would create a new view controller here as well
navigationController?.pushViewController(vueGroupe, animated: true)
vueListe.navigationItem.title = "Groupe View";
case "Categorie":
let vueCat = VueListeViewController() // New instance
service.getCategorie(ids: elem!)
navigationController?.pushViewController(vueCat, animated: true)
vueListe.navigationItem.title = "Groupe View";
我有一个列表,我想显示它 3 次(当我单击特定单元格时,从一个列表到另一个列表)。为此,我正在使用包含我的 ListView 的 XIB。我还设置了一个 NavigationController 来播放推送动画。
这就是我在 rootViewController 中调用 pushViewController 方法的方式。
case "Groupe" :
//this is OK since it's the first time I push the ViewController
service.getGroupe()
let vueGroupe = vueListe!
navigationController?.pushViewController(vueGroupe, animated: true)
vueListe.navigationItem.title = "Groupe View";
case "Categorie" :
//this is not
let vueCat = vueListe!
service.getCategorie(ids: elem!)
navigationController?.pushViewController(vueCat, animated: true)
vueListe.navigationItem.title = "Groupe View";
使用此代码我得到以下错误:
"Pushing the same view controller instance more than once is not supported"
如何多次推送同一个 ViewController?
您应该创建 UIViewController
对象的新实例并推送它。
因此,在您的代码中,它将类似于:
case "Groupe":
service.getGroupe()
let vueGroupe = VueListeViewController() // I would create a new view controller here as well
navigationController?.pushViewController(vueGroupe, animated: true)
vueListe.navigationItem.title = "Groupe View";
case "Categorie":
let vueCat = VueListeViewController() // New instance
service.getCategorie(ids: elem!)
navigationController?.pushViewController(vueCat, animated: true)
vueListe.navigationItem.title = "Groupe View";