2

有了这段代码,为什么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)
    }
}

正如您在以下屏幕截图中看到的,应该领先的 navigationBarItem 没有显示:

有问题的截图!

4

1 回答 1

5

对于双方项目都使用这个变体(测试为与 Xcode 11.2 / iOS 13.2 一起使用):

ScrollView {
    changePassword
}
.navigationBarItems(leading: backButton, trailing: finishButton)
于 2020-01-05T14:03:29.533 回答