私のターゲットには、ユーザーのアクションごとに異なるビューをモーダルに提示する必要がある多くのビューが含まれています。ここでは、よりクリーンなビュー階層とより良いユーザーエクスペリエンスを得るために私がしたいことを説明します。
- ルートビューコントローラーは、ファーストビューコントローラーをモーダルに提示します
- First View Controllerのボタンをクリックすると、Second ViewControllerがモーダルに表示されます。
- 2番目のViewControllerが表示されたらすぐに、最初のControllerを表示階層から削除または削除したいと思います。
それをしてもいいですか?もしそうなら、私はそれをどのようにすべきですか?
そうでない場合、これを解決する正しい方法は何ですか?私は各ビューに多くのモーダルに提示されたビューコントローラーを提示します。現在のビューを閉じたい場合でも、現在のビューを閉じても前のビューは表示されたままになると思います。
更新:
VC1(ルート)> VC 2(モーダルに存在)> VC 3( VC 2上にモーダルに存在)
を閉じるVC3
と、VC2
はまだビューメモリにあります。そのため、VC2
却下するVC3
とすぐに表示されたくはなく、代わりにビュー階層をVC1
削除または却下VC2
して表示したいと思います。
WANT:私は青を閉じたときの画像では、私は私の見解メモリにピンクのを見たくないと私はすぐに青い1が表示されるようにそれを削除したいです。
それが私がやりたいことです。
何か助けがありますか?ありがとう。
したがって、次のようなストーリーボードがあると仮定しましょう。
何が起こるべきか:
3番目のViewControllerボタンのアクション:
@IBAction func tapped(_ sender: Any) {
presentingViewController?.presentingViewController?.dismiss(animated: true, completion: nil)
}
ご覧のとおり、現在のViewControllerのpresentingViewControllerにアクセスすることで、ViewControllerの以前の階層を閉じることができます。
このビューコントローラーを提示したビューコントローラー。
それを実装presentingViewController?.presentingViewController?
することにより、次のことを意味します:提示された現在のViewControllerの提示:)
少し紛らわしいように思えるかもしれませんが、非常に簡単です。
So the output should be like (I added background colors to the viewControllers -as vc1: orange, vc2: black and vc3: light orange- to make it appears clearly):
EDIT:
If you are asking to remove the ViewController(s) in the middle (which in this example the second ViewController), dismiss(animated:completion:) does this automatically:
If you present several view controllers in succession, thus building a stack of presented view controllers, calling this method on a view controller lower in the stack dismisses its immediate child view controller and all view controllers above that child on the stack. When this happens, only the top-most view is dismissed in an animated fashion; any intermediate view controllers are simply removed from the stack. The top-most view is dismissed using its modal transition style, which may differ from the styles used by other view controllers lower in the stack.
Referring to what are you asking:
I think even if I want to dismiss current view, the previous one will still remain appear when current one dismiss.
それはUIにはっきりと表示されていると思います(そして私はそれで問題ないと思います)が、dismiss
ドキュメントの説明で述べたように、3番目と2番目の両方がスタックから削除されます。それが正しい方法です。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加