英文:
Navigation Bar back button disappears after showing an alert
问题
我有一个简单的视图:
struct AccountView: View {
@State private var showingLogoutAlert = false
var body: some View {
Button("Log out!") {
showingLogoutAlert = true
}
.alert(isPresented: $showingLogoutAlert, content: {
Alert(title: Text("Log out of Flow?"),
primaryButton: .cancel(),
secondaryButton: .destructive(Text("Log out"), action: {
//logOut()
}))
})
}
}
当你点击按钮时,会显示一个警告。问题是,警告消失后,返回按钮也消失了!我不知道为什么会发生这种情况。请看下面的gif图示。
[![enter image description here](https://i.stack.imgur.com/MxAWC.gif)](https://i.stack.imgur.com/MxAWC.gif)
我已经尝试将问题减少到最少的代码。在一个单独的新应用程序中复制了它。仍然存在相同的问题。
英文:
I have a simple view:
struct AccountView: View {
@State private var showingLogoutAlert = false
var body: some View {
Button("Log out!") {
showingLogoutAlert = true
}
.alert(isPresented: $showingLogoutAlert, content: {
Alert(title: Text("Log out of Flow?"),
primaryButton: .cancel(),
secondaryButton: .destructive(Text("Log out"), action: {
//logOut()
}))
})
}
}
When you tap the button, it will show an alert. The problem is, after the alert dismisses, the back button also disappears! I have no idea why this is happening. See the gif below.
I've tried to reduce the problem down to the bare minimum code. Replicated it on a separate, new app. Still the same issue.
答案1
得分: 0
这是我在我的测试中使用的工作代码,在MacOS 13.2、Xcode 14.2上进行了测试,已在真实的iOS 16.3设备(而非预览)和macCatalyst上测试。
struct ContentView: View {
var body: some View {
NavigationStack {
NavigationLink(destination: AccountView()) {
Text("AccountView")
}
}
}
}
struct AccountView: View {
@State private var showingLogoutAlert = false
var body: some View {
Button("Log out!") {
showingLogoutAlert = true
}
.alert(isPresented: $showingLogoutAlert, content: {
Alert(title: Text("Log out of Flow?"),
primaryButton: .cancel(),
secondaryButton: .destructive(Text("Log out"), action: {
//logOut()
}))
}
}
}
希望这对你有帮助。
英文:
this is the working code I used in my test, on MacOS 13.2, Xcode 14.2, tested on real ios 16.3 devices (not Previews), and macCatalyst.
struct ContentView: View {
var body: some View {
NavigationStack {
NavigationLink(destination: AccountView()) {
Text("AccountView")
}
}
}
}
struct AccountView: View {
@State private var showingLogoutAlert = false
var body: some View {
Button("Log out!") {
showingLogoutAlert = true
}
.alert(isPresented: $showingLogoutAlert, content: {
Alert(title: Text("Log out of Flow?"),
primaryButton: .cancel(),
secondaryButton: .destructive(Text("Log out"), action: {
//logOut()
}))
})
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论