I have obviously missed some subtle bit of code but I can't see what I am missing. I am getting a warning about my NavigationLink.
Result of 'NavigationLink<Label, Destination>' initializer is unused
Below I have included the code that has caused the warning and the code of the target of the Navigation link. The link does not work, though the button does, as proved by the print statement (see below). Here is the code that caused the warning:
import SwiftUI
import SwiftData
struct Main_Menu_iPad: View {
@Environment(\.modelContext) private var context
@Query private var readings: [Readings]
var body: some View {
ZStack {
Image("iPad Background 810 X 1060")
.resizable()
.scaledToFill()
.ignoresSafeArea()
VStack {
HStack{
Image("Diabetes Control Logo 1024X1024")
.resizable()
.frame(width: 100, height: 100, alignment: .leading)
.padding(.leading, 40)
Text("Diabetes Control")
.font(Font.custom("SnellRoundhand-Black", size: 40))
.background(Color(red: 255, green: 253, blue: 208))
.shadow(color: Color(red: 128, green: 128, blue: 128), radius: 3)
.padding(.leading, 150)
Spacer()
}.padding(.bottom, 35)
HStack {
Text("What would you like to do : ")
.font(Font.custom("SnellRoundhand-Black", size: 30))
.background(Color(red: 128, green: 128, blue: 128))
.shadow(color: Color(red: 126, green: 128, blue: 128), radius: 3)
Spacer()
}.padding(.leading, 35)
.padding(.bottom,35)
NavigationStack {
HStack {
Button {
print("I have been pressed")
NavigationLink {
iPadReadingsEntry()
} label: {
Text("Enter a BLOOD Glucose reading")
}
} label: {
Text("Enter a Blood Glucose Reading")
}.background(Color(red: 255, green: 253, blue: 208))
.foregroundColor(.black)
.font(Font.custom("SnellRoundhand", size: 24))
Spacer()
}.padding(.leading, 60)
.padding(.bottom, 25)
Spacer()
}.background(.blue)
Spacer()
}
}
}
}
#Preview {
Main_Menu_iPad()
}
And this is the code of the target view:
import SwiftUI
struct iPadReadingsEntry: View {
var body: some View {
ZStack {
Image("iPad Background 810 X 1060")
.resizable()
.scaledToFill()
.ignoresSafeArea()
VStack {
HStack{
Image("Diabetes Control Logo 1024X1024")
.resizable()
.frame(width: 100, height: 100, alignment: .leading)
.padding(.leading, 40)
Text("Diabetes Control")
.font(Font.custom("SnellRoundhand-Black", size: 40))
.background(Color(red: 255, green: 253, blue: 208))
.shadow(color: Color(red: 128, green: 128, blue: 128), radius: 3)
.padding(.leading, 150)
Spacer()
}.padding(.bottom, 35)
Spacer()
}
}
}
}
#Preview {
iPadReadingsEntry()
}
Finally is there a way of switching View without using a NavigationStack/NamigastinLink as it covers my background image?