navigationControllerを利用して
画面A → 画面B → 画面C と遷移してきた状態で画面Dをpushして表示させ、
ナビゲーションの履歴を
画面A → 画面B → 画面D
として画面Dの戻り先を画面Bにしたいです。
次の画面Dをpushする前にナビゲーションスタックを書き換えてあげればいいのかと思い、
画面Cで以下のようにしました。
swift
1var aHistory = navigationController?.viewControllers 2print("hogehistory1:(aHistory!)") 3aHistory?.removeLast() 4print("hogehistory2:(aHistory!)") 5navigationController?.viewControllers = aHistory! 6print("hogehistory3:(navigationController?.viewControllers)") 7navigationController?.pushViewController(DViewController(), animated: false) 8
DViewControllerがpushされず、D画面に遷移しません。B画面が表示されます。
print結果は以下のようになりました。
hogehistory1:[<xxx.AViewController: 0x1028e7200>, <xxx.BViewController: 0x1028bda00>, <xxx.CViewController: 0x1028baa00>]
hogehistory2:[<xxx.AViewController: 0x1028e7200>, <xxx.BViewController: 0x1028bda00>]
hogehistory3:nil
swift
1navigationController?.viewControllers = aHistory!
この部分を消すとpushはできるのですが...
どのような処理にすれば実現できますでしょうか?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。