SwiftUI:NavigationBarItem 未显示

Cle*_*vic 2 swift swiftui swiftui-navigationlink

有了这段代码,为什么 navigationBarItem 没有显示出来?该视图在工作表中被调用,但这在之前并不重要......

struct ChangePasswordView: View {
    @Environment(\.presentationMode) private var presentationMode

    @State private var passwordNew = ""
    @State private var passwordNewAgain = ""

    var body: some View {
        ScrollView {
            changePassword
        }
        .navigationBarItems(leading: backButton)
        .navigationBarItems(trailing: finishButton)
    }

    var backButton: some View {
        Button(action: { self.presentationMode.wrappedValue.dismiss() }) {
            Text("Cancel")
        }
    }

    var finishButton: some View {
        Button(action: {
            self.changePasswordGlobally()
            self.presentationMode.wrappedValue.dismiss()
        }) {
            Text("Apply")
        }
        .disabled(self.passwordNew.isEmpty || self.passwordNew != self.passwordNewAgain)
        .disableAutocorrection(true)
    }
}
Run Code Online (Sandbox Code Playgroud)

正如您在以下屏幕截图中看到的那样,应该引导的 navigationBarItem 没有显示:

有问题的截图!

Asp*_*eri 5

对于双方项目,请使用此变体(测试与 Xcode 11.2 / iOS 13.2 一起使用):

ScrollView {
    changePassword
}
.navigationBarItems(leading: backButton, trailing: finishButton)
Run Code Online (Sandbox Code Playgroud)