Reputation: 383
I am designing a simple iOS application that performs a few simple calculation then presents the results on a second View.
The views are:
In the previous days of Xcode, one could present the second view within a ButtonView. Now that I am using Xcode 16.0 with iOS 18.0 things look like they have changed.
Can I present the ResultsView using a Button ??
The code for the ContentView follows"
import SwiftUI
struct ContentView: View {
@Bindable var rData = ResonantData()
@Bindable var dData = DesiredData()
var body: some View {
NavigationStack {
ZStack {
Color(.black)
.ignoresSafeArea()
VStack{
Title()
Spacer()
Notes()
// Creates the top GroupBox
GroupBox(label: Label("Resonant", systemImage: "chart.bar.fill")
.foregroundColor(.blue)
.fontWeight(.bold)){
Text("Enter in the field below, the Current Resonant Frequency (Mhz), as seen on your Analyser.")
TextField("Resonance (Mhz)", text: $rData.frequency)
.keyboardType(.numberPad)
}.padding()
// Creates the bottom GroupBox
GroupBox(label: Label("Desired", systemImage: "antenna.radiowaves.left.and.right.circle")
.foregroundColor(.red)
.fontWeight(.bold)){
Text("Enter in the field below, the Desired Resonant Frequency (Mhz).")
TextField("Desired (Mhz)", text: $dData.frequency)
.keyboardType(.numberPad)
}.padding()
Spacer()
Button("Results View") {
ResultsView()
}
}
}
}
}
}
#Preview {
ContentView()
}
struct Title: View {
var body: some View {
VStack {
HStack {
Group {
Image(systemName: "s.circle.fill")
Image(systemName: "w.circle.fill")
Image(systemName: "r.circle.fill")
}
.font(.system(size: 50))
.foregroundColor(.yellow)
}
Text("Adjust")
.font(.system(size: 30))
.foregroundColor(.white)
.padding(.top, 1)
}
}
}
struct Notes: View {
var body: some View {
VStack {
Text("Note:")
.fontWeight(.bold)
.font(.system(size: 20))
.foregroundStyle(.yellow)
.padding(.trailing, 320)
Text("SWR Adjust is a simple Application that allows you to adjust the SWR ratio of your Dipole and Verticle antenna.")
.fontWeight(.medium)
.font(.system(size: 18))
.foregroundStyle(.white)
.padding(.leading)
}
}
}
And the code for the ResultsView is:
import SwiftUI
struct ResultsView: View {
var body: some View {
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
}
}
#Preview {
ResultsView()
}
Upvotes: 0
Views: 36