我有一个列表,我想显示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";
使用此代码,我得到以下错误:
“不支持多次按下同一视图控制器实例”
如何多次推送同一个ViewController?
答案 0 :(得分:1)
您应该创建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";