無法解除模態視圖控制器並返回到根視圖控制器。動畫確實顯示,但仍彈出當前的視圖控制器。無法解除模態視圖控制器
我正在開發的應用程序沒有使用storyboard,我想解僱當前的模式視圖控制器和回到根視圖控制器。
有沒有適當的方法來做到這一點?
我的根控制器是導航控制器雖然我的模式 - 視圖 - 控制器是的UIViewController。這是不工作的根本原因嗎?
模態視圖控制器(PlayerViewController)
func handleBack() {
self.view.window?.rootViewController?.dismiss(animated: true, completion: nil)
}
FeedCell.swift中的HomeController(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
}
郵編,沒有想象 – Tj3n
@ Tj3n完成編輯 – aznelite89
代碼後重新添加按鈕,在'模式視圖控制器(PlayerViewController) ' – Vinodh