2016-11-21 14 views
3

モーダルビューコントローラを閉じてルートビューコントローラに戻ることができません。アニメーションは表示されましたが、現在のビューコントローラーが引き続き表示されます。モーダルビューコントローラを閉じることができません

私はストーリーボードを使わずにアプリケーションを開発しています。私は現在のモーダルビューコントローラーを却下し、ルートビューコントローラーに戻したいと思います。

これを行うには適切な方法はありますか?

ルートコントローラーがナビゲーションコントローラーモーダル表示コントローラーがの場合、UIViewControllerです。それは働かない根本的な原因ですか?

モーダルビューコントローラ(PlayerViewController)

func handleBack() { 
    self.view.window?.rootViewController?.dismiss(animated: true, completion: nil) 
} 

にHomeControllerでFeedCell.swift(FeedCell.swift)

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { 
    let playerViewController = PlayerViewController() 
    playerViewController.modalPresentationStyle = .overCurrentContext 
    self.window?.rootViewController?.present(playerViewController, animated: true, completion: nil) 
} 

AppDelegate

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 

    window = UIWindow(frame: UIScreen.main.bounds) 
    window?.makeKeyAndVisible() 

    let layout = UICollectionViewFlowLayout() 
    window?.rootViewController = UINavigationController(rootViewController: HomeController(collectionViewLayout: layout)) 

    UINavigationBar.appearance().barTintColor = UIColor.rgb(red: 230, green: 32, blue: 31) 

    // get rid of black bar underneath navbar 
    UINavigationBar.appearance().shadowImage = UIImage() 
    UINavigationBar.appearance().setBackgroundImage(UIImage(),for: .default) 

    application.statusBarStyle = .lightContent 

    let statusBarBackgroundView = UIView() 
    statusBarBackgroundView.backgroundColor = UIColor.rgb(red: 194, green: 31, blue: 31) 

    window?.addSubview(statusBarBackgroundView) 
    window?.addConstraintsWithFormat(format: "H:|[v0]|", views: statusBarBackgroundView) 
    window?.addConstraintsWithFormat(format: "V:|[v0(20)]", views: statusBarBackgroundView) 

    return true 
} 

示したでした「タップ」しかし、あなたはモーダルとして発表された現在のビューコントローラを却下する場合は、ビューコントローラを提示された1つを呼び出し、提示ビューを却下することを教えてください enter image description here

+5

ポストコードは、Tj3n @ – Tj3n

+0

が – aznelite89

+0

ポストコードは、モーダルビューコントローラ(PlayerViewController)コードの ' – Vinodh

答えて

1
let layout = UICollectionViewFlowLayout() 
let navController = UINavigationController(rootViewController: HomeController(collectionViewLayout: layout)) 
window?.rootViewController = navController 

はこれを試してみてください。

+1

ブラボー、チャームのように働いた – aznelite89

+0

ありがとう、兄。驚くほど発展する日がありますか? –

1

を働いていない却下コントローラ:

self.presentingViewController?.dismissViewControllerAnimated(true, completion: nil) 

presentingViewController

このビューコントローラを提示ビューコントローラ。

+0

こんにちはおかげ'に戻るボタンを追加するが、それは動作していない、編集完了ピクチャではありません。 – aznelite89

+0

モーダルVCファイルである表示されたビューコントローラから直接呼び出しを呼び出す必要があります。 – OhadM

+0

まだ動作していませんが、まだ動作していません。私のルートコントローラはナビゲーションコントローラで、私のモーダルビューコントローラはUIViewControllerです。 – aznelite89

0

どんなのViewControllerを閉じ、あなたはこれを試してみてください

func handleBack() { 
     self.dismiss(animated: true, completion: {}) 
    } 
0

を使用する必要があります。

_ = self.navigationController?.popToRootViewController(animated: true) 
関連する問題