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      

BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

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.