UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

SOLVED: NavigationBar too big

Forums > SwiftUI

Hello Guys, I am a beginner in SwiftUI, following the 100 days challenge. In my first app, there is this List in a NavigationView leading onto another NavigationView if tapped on an entry, but the title is totally misplaced downwards... I tried disabling the NavigationBar, it worked but the animation disappeared and the back button did also. Would be nice if i could maintain the animation of the title and also the back button, but also get the title into the right position!

import SwiftUI

struct EditMoneyView: View {
    @Environment(\.managedObjectContext) var managedObjContext
    @Environment(\.dismiss) var dismiss

    var money: FetchedResults<Money>.Element

    @State private var name = ""
    @State private var amount = Double()
    @State private var currency = "EUR"

    var body: some View {
        NavigationView {
        Form {
            Section {
                TextField("\(money.name!)", text: $name)
                    .onAppear {
                        name = money.name!
                        amount = money.amount
                    }
                VStack {
                    Text("Test")
                    TextField("\(amount)", value: $amount, format: .currency(code: currency))
                        .keyboardType(.numberPad)
                }

                HStack {
                    Spacer()
                    Button("Fertig") {
                        DataController().editMoney(money: money, name: name, amount: amount, context: managedObjContext)
                        dismiss()
                    }
                    Spacer()
                    }
                }
            .navigationViewStyle(StackNavigationViewStyle())
            .navigationBarTitle("Bearbeiten")
            }
        }
    }
}

https://imgur.com/a/lrPI2cX

This is the misplaced title

Thank you all very much!

1      

hello Marcii,

your problem description is

there is this List in a NavigationView leading onto another NavigationView if tapped on an entry

so you have two NavigationViews, one inside the other (!). remove the NavigationView wrapper on the second view.

if you are in a view enclosed in a NavigationView and follow a NavigationLink to a second view, that second view inherits the NavigationView from the first view. (inherit may not be exactly the right term here, but it's sufficient.)

hope that helps,

DMG

2      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.