我可以使用一些建议来获得我的导航链接,以提醒我工作。该代码是正确的,我收到一条错误消息,提示“未使用'NavigationLink'初始化程序的结果”。
@State private var mainScreenReturn = false
@State private var gameOver = false
.alert(isPresented: $gameOver) {
Alert(title: Text("Game Over"), message: Text("Tighten Up!"), primaryButton: .destructive(Text("Main Menu")) {
self.mainMenu()
}, secondaryButton: .default(Text("Play Again"), action: { self.playAgain() }))
}
func mainMenu() {
DispatchQueue.main.async {
self.mainScreenReturn = true
}
NavigationLink(destination: ContentView(), isActive: self.$mainScreenReturn,
label: { EmptyView() })
}
func playAgain() {
// reset timer and score
self.timeRemaining = 2; self.score = 0
}
func endGame() {
// warm up haptics
self.feedBack.prepare()
// vibrate
self.feedBack.notificationOccurred(.error)
// show game over alert
self.gameOver = true
// set time to 0
self.timeRemaining = 0
// play sound file
playSound(sound: "CasingDrop", type: "wav")
}
我也试图将导航链接移到视图正下方但同样的问题。
var body: some View {
NavigationView {
ZStack {
NavigationLink(destination: ContentView(), isActive: self.$mainScreenReturn,
label: { EmptyView() })
}
}
提前谢谢!