gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 10:29:15 26 4
gpt4 key购买 nike

  1. 新的 PopUp ViewController 出现 .overCurrentContext
  2. PopUp View 中有 2 个可导航的按钮,可用于其他 2 个 View 。
  3. 诸如print之类的简单操作进展顺利,但是当我尝试以编程方式进行segue时(来自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()
}

}

最佳答案

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

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

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

因此,对 Controller 的引用解决了这个问题。可以导航到一边,直到调用新的 subview 、单独的 View 。

在本例中有效的代码:

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

结论。简单有两种方法:

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

关于Swift NavigationController 推送方法请求在 PopUp View 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59468622/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com