画面遷移を複数回して後に、一気に最初の画面に戻りたいと思っています。
現在は以下の順番で画面遷移しております。
FirstViewController → SecondViewController → CollectionViewController
FirstViewControllerからSecondViewControllerへはstoryboardでsegueを設定して遷移しており、特にコードは書いておりません。
SecondViewControllerにはボタンを配置しており、ボタンをタップするとCollectionViewControllerに遷移します。
そのコードが以下になります。
swift
1 let collectionView:CollectionViewController = storyboard!.instantiateViewController(withIdentifier: "ThirdView") as! CollectionViewController 2 self.present(collectionView, animated: true, completion: nil)
ここまでは正常に動いております。
CollectionViewControllerでセルをタップしたら、一気に最初の画面に戻りたいので以下のように書いてエラーが出ました。
swift
1let vc = storyboard!.instantiateViewController(withIdentifier: "top") as! FirstViewController 2self.present(vc, animated: true, completion: nil)
// エラー内容 Warning: Attempt to present <test.FirstViewController: 0x13e619dc0> on <test.CollectionViewController: 0x13e612880> which is already presenting
FirstViewControllerから遷移してきて、まだFirstViewControllerが残っているのだと思いますが、解決方法がわかりません。
戻るときに最初に起動したときと同じように操作したいので、インスタンスなどは全て破棄できるなら破棄して、最初の画面に戻りたいです。
よろしくお願いします。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2017/03/01 09:04 編集