我使用 UIKit 和 swiftUI 构建了一个应用程序。
它在 ios13.1 上运行良好,但在 ios 13.2 上我有错误:
我在UIViewController中显示SwiftUI 视图(使用HostingController)。此视图由包含在NavigationLink中的元素组成。单击此元素时,尽管导航栏正常,但不会显示下一个视图,并且单击返回时,应用程序崩溃并显示:
<Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Tried to pop to a view controller that doesn't exist.'>
它是与 ios 13.2 相关的错误吗?任何线索如何解决它?
这是我的代码:
用户界面控制器:
< 类 MyController: UIViewController {
var delegate: MenuItemsDelegate?
let vc = UIHostingController(rootView: MyView_UI())
override func viewDidLoad() {
super.viewDidLoad()
if #available(iOS 13.0, *) {
view.backgroundColor = BACKGROUND_COLOR_D
} else {
view.backgroundColor = PALE_GREY
}
setupViews()
setNavigationBar()
}
func setupViews() {
addChild(vc)
view.addSubview(vc.view)
vc.didMove(toParent: self)
setupConstraints()
}
func setupConstraints() {
vc.view.translatesAutoresizingMaskIntoConstraints = false
[
vc.view.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor),
vc.view.centerXAnchor.constraint(equalTo: view.centerXAnchor),
vc.view.widthAnchor.constraint(equalTo: view.widthAnchor),
vc.view.bottomAnchor.constraint(equalTo: view.bottomAnchor),
].forEach {$0.isActive = true }
}
func setNavigationBar() {
title = ""
navigationItem.leftBarButtonItem = UIBarButtonItem(image: #imageLiteral(resourceName: "slidingNotif").withRenderingMode(.alwaysOriginal), style: .plain, target: self, action: #selector(handleMenuToggle))
setNavigationRightBarButtons()
}
@objc func handleMenuToggle() {
delegate?.handleMenuToggle(forMenuOption: nil)
}
} >
MyView_UI: < var body: 一些视图 {
ScrollView{
VStack(spacing: 15) {
HStack(alignment: .center, spacing: 20) {
NavigationLink(destination: SecondView_UI(some param )){
ThirdView_UI(some param), height: 150)
}
NavigationLink(destination: SecondView_UI(some param)){
ThirdView_UI(some, height: 150)
}
}
.buttonStyle(PlainButtonStyle())
//autres HStack(...)
}
}
}
>
MyView_UI 和 SecondView_UI 显示正常,但返回时应用程序崩溃