ViewController
弹出的弹出窗口.overCurrentContext
一个简单的动作,例如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()
}
}
答案 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)
结论。很简单,有两种方法:
UINavigationController