I built an app using both UIKit and swiftUI.
It worked fine with ios13.1 but with ios 13.2 I have bugs:
I'm showing a SwiftUI View in a UIViewController (using HostingController). This view is composed with elements wrapped in NavigationLink. When clicking on this element, the next view doesn't show, although the navbar is ok, and when clicking back, the app crashes with:
<Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Tried to pop to a view controller that doesn't exist.'>
Is it a bug related to ios 13.2 ? Any clue how to fix it ?
Here is my code:
UIController :
< class 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: some View {
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 and SecondView_UI are showing fine, but app crashes when going back