全ての画面において、ホームボタンを押下するとモーダルを閉じ、一番最初の画面に戻る処理を実装したいです。
通常の進行方向で遷移している場合は正しく動作しますが、
navigationbarの戻るボタン押下またはnavigationController?.popToRootViewController(animated: true)での画面遷移後にはモーダルを閉じる処理(self.dismiss(animated: true, completion: nil))が実行されません。
戻った後に通常の進行方向で遷移し、表示した画面では処理が正しく動作します。
現在は以下の順番で画面遷移しております。
navigationController → loginViewController →(present Modally) navigationController →(show) FirstViewController →(show) SecondViewController →(show) ThirdViewController
モーダルを閉じる処理はAppDelegateからすべての画面で継承しているRootViewControllerを呼び出し、動作させています。
swift
1lass AppDelegate: UIResponder, UIApplicationDelegate { 2 var rootViewController: RootViewController! 3 4 func applicationDidEnterBackground(_ application: UIApplication) { 5 let appDelegate = UIApplication.shared.delegate as! AppDelegate 6 appDelegate.rootViewController.logout() 7 } 8}
swift
1class RootViewController: UIViewController { 2 3 override func viewDidLoad() { 4 super.viewDidLoad() 5 6 var appDelegate:AppDelegate = UIApplication.shared.delegate as! AppDelegate 7 appDelegate.rootViewController = self 8 } 9 10 public func logout() { 11 self.dismiss(animated: true, completion: nil) 12 } 13}
よろしくお願い致します。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。