2

I have a large iOS app with swift and XIBs for the view controllers. Now I'm progressively migrating from XIBs/View controllers to SwiftUI but I don't know how to solve a specific problem.

Some XIB/View controllers have a navigation bar, if these XIB/controllers push a SwiftUI view the SwiftUI view appears correctly with its content and the navigation bar inherited from its parent XIB view. But some of the SwiftUI views need to change some of the inherited navigation bar buttons and I don't know how to access from the SwiftUI code to the navigation bar content.

I tried to hide the inherited navigation bar using

.navigationBarTitle("")
.navigationBarHidden(true)

(which is working) and creating a SwiftUI navigationbar using NavigationView component, but:

  1. I don't know if this is the correct approach.

  2. Using this NavigationView component the new navigation bar shown is much higher than the inherited navigation bar. Why is it showing a much higher navbar? Could I change this heght and how?

Thank you!

2
  • You can use standard init() then access the traditional UIKit style navigation modifications. Commented Apr 2, 2022 at 4:17
  • Don't mix UIKit navigation engine and SwiftUI one - they do not cooperate. In your case it is better to transfer management of navigation (callbacks, KVO, etc.) via view model from UIKit into SwiftUI part. Commented Apr 2, 2022 at 8:55

1 Answer 1

1

Well, I've just discovered that I have this method:

.navigationBarItems(leading: View, trailing: View) 

So I can customize my navbar buttons with it. I don't need to hide the inherited navbar, just customize it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.