gpt4 book ai didi

SwiftUI:NavigationBarItem 前导不显示

转载 作者:行者123 更新时间:2023-12-05 01:13:50 25 4
gpt4 key购买 nike

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

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 未显示:

Screenshot with the problem!

最佳答案

对于两侧项目使用此变体(测试与 Xcode 11.2/iOS 13.2 一起使用):

ScrollView {
changePassword
}
.navigationBarItems(leading: backButton, trailing: finishButton)

关于SwiftUI:NavigationBarItem 前导不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59599896/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com