我同时使用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相关的错误吗?任何提示如何解决它?
这是我的代码:
UIController:
<类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正常显示,但是返回时应用崩溃