次のビューコントローラーがモーダルに表示されたらすぐに、以前のモーダルに表示されたビューコントローラーを閉じるか削除します

ティハ・アウン

私のターゲットには、ユーザーのアクションごとに異なるビューをモーダルに提示する必要がある多くのビューが含まれています。ここでは、よりクリーンなビュー階層とより良いユーザーエクスペリエンスを得るために私がしたいことを説明します。

  1. ルートビューコントローラーは、ファーストビューコントローラーをモーダルに提示します
  2. First View Controllerのボタンをクリックすると、Second ViewControllerがモーダルに表示されます。
  3. 2番目のViewControllerが表示されたらすぐに、最初のControllerを表示階層から削除または削除したいと思います。

それをしてもいいですか?もしそうなら、私はそれをどのようにすべきですか?

そうでない場合、これを解決する正しい方法は何ですか?私は各ビューに多くのモーダルに提示されたビューコントローラーを提示します。現在のビューを閉じたい場合でも、現在のビューを閉じても前のビューは表示されたままになると思います。

更新:

VC1(ルート)> VC 2(モーダルに存在)> VC 3( VC 2上にモーダル存在)

を閉じるVC3と、VC2はまだビューメモリにあります。そのため、VC2却下するVC3すぐに表示さたくはなく、代わりにビュー階層をVC1削除または却下VC2して表示たいと思います。

ここに画像の説明を入力してください

WANT:私は青を閉じたときの画像では、私は私の見解メモリにピンクのを見たくないと私はすぐに青い1が表示されるようにそれを削除したいです。

それが私がやりたいことです。

何か助けがありますか?ありがとう。

アフマドF

したがって、次のようなストーリーボードがあると仮定しましょう。

ここに画像の説明を入力してください

何が起こるべきか:

  • (最初のViewControllerからの)2番目のViewControllerを提示します。
  • (2番目のViewControllerからの)3番目のViewControllerを提示します。
  • (3番目のViewControllerからの)最初のViewControllerに却下します。

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]

編集
0

コメントを追加

0

関連記事

Related 関連記事

ホットタグ

アーカイブ