Swift NavigationController推送方法请求在PopUp视图中不起作用

时间:2019-12-24 12:08:35

标签: swift popup segue

  1. ViewController弹出的弹出窗口.overCurrentContext
  2. 从弹出窗口视图中有2个带有导航按钮,用于另外2个视图。
  3. 一个简单的动作,例如print很好,但是当我尝试以编程方式(从xib文件,popUpViewController)进行搜索时,什么也没发生。

    let vc = RegisterEmailViewController.instantiate()
    vc.coordinator = self
    navigationController.pushViewController(vc, animated: false)
    

从任何其他角度来看都很顺利。 怎么了?

PopUpViewController代码:

//  Created by ᴀʟᴇxᴀɴᴅʀ ᴢʜᴇʟɪᴇᴢɴɪᴀᴋ on 23.12.2019.
//  Copyright © 2019 ᴀʟᴇxᴀɴᴅʀ ᴢʜᴇʟɪᴇᴢɴɪᴀᴋ. All rights reserved.

import UIKit

class ViewController: UIViewController, Storyboarded {
    weak var coordinator: MyCoordinator?

    @IBAction func dismissPopUp(_ sender: Any) {
        dismiss(animated: false, completion: nil)
    }

    @IBAction func buttonEmail(_ sender: Any) {
        let vc = UIStoryboard.init(name: "Main", bundle: Bundle.main).instantiateViewController(withIdentifier: "EmailViewController") as? EmailViewController
        self.navigationController?.pushViewController(vc!, animated: true)
    }

    @IBAction func buttonPhone(_ sender: Any) {
        let vc = UIStoryboard.init(name: "Main", bundle: Bundle.main).instantiateViewController(withIdentifier: "PhoneViewController") as? PhoneViewController
        self.navigationController?.pushViewController(vc!, animated: true)
    }

    override func viewDidLoad() {
        super.viewDidLoad()
    }

}

1 个答案:

答案 0 :(得分:0)

MyCoordinator会初始化所有导航,并且不能让我自己简单地进行搜索/导航。

var childCoordinators = [Coordinator]()
var navigationController: UINavigationController

init(navigationController: UINavigationController) {
    self.navigationController = navigationController
}

因此,对控制器的引用解决了该问题。可以导航到一边,直到调用新的子视图为止。

在这种情况下有效的代码:

    let vc = RegisterEmailViewController.instantiate()
    vc.coordinator = self
    navigationController.pushViewController(vc, animated: false)

结论。很简单,有两种方法:

  1. 删除所有依赖项和其他使用 UINavigationController
  2. 仅通过新方法进行声明以供全局使用。