This is the RgistrationDetailView where I want to pass a selected value from RegistrationRowView
I changed “Clinician’s Name” to selection: RegistrationRowView(choiceMade: “”)
recieved the following.
error ?
Struct ‘ViewBuilder’ requires that ‘EmptyTableRowContent<V>’ conform to ‘View’
Struct ‘ViewBuilder’ requires that ‘TableHeaderRowContent<V, Text>’ conform to ‘View’
Static method ‘buildExpression’ requires that ‘LabeledContent<Text, Text>’ conform to ‘TableRowContent’
I was trying to return selected values of choicemade and choicemade2 from Registration Row View to Registration Detail View, in order to pass the selected choicemade and selected choice made2 options to RegistrationDetailView, so that I can save the Data in CoreData.
//
// RegistrationDetailView.swift
// Registration
//
// Created by Bibin Mathew on 7/2/24.
//
import SwiftUI
struct RegistrationDetailView: View
{
var body: some View
{
List
{
Section("General")
{
LabeledContent
{
Text("First Name Here")
}
label:
{
Text("Enter First Name Here")
}
LabeledContent
{
Text("Last Name Here")
}
label:
{
Text("Enter Last Name Here")
}
LabeledContent
{
Text(.now, style: .date)
}
label:
{
Text("Appointment Date")
}
LabeledContent
{
Text(selection: RegistrationRowView(choiceMade: ""))
}
label:
{
Text("Select Clinician's Name")
}
LabeledContent
{
Text("Reason for visit")
}
label:
{
Text("Select Reason For Vist")
}
}
}
}
}
#Preview
{
RegistrationDetailView()
}
//
// RegistrationRowView.swift
// Registration
//
// Created by Bibin Mathew on 7/2/24. //
import SwiftUI
struct RegistrationRowView: View {
let dateFormatter: DateFormatter =
{
let formatter = DateFormatter()
formatter.dateStyle = .long
return formatter
}()
@State private var AppointmentDate = Date.now
@State private var FirstName: String = ""
@State private var LastName: String = ""
@State var choiceMade = "Select Clinician's Name"
@State var choiceMade2 = "Select Reason for visit"
var body: some View
{
NavigationStack
{
List
{
VStack
{
DatePicker(selection: $AppointmentDate, in: ...Date.now, displayedComponents: .date)
{
Text("Appointment Date")
}
Text("Appointment Date is (AppointmentDate, formatter: dateFormatter)").font(.custom("Chalkduster", size: 15))
}
VStack {
TextField(
"First Name",
text: $FirstName
).textFieldStyle(.roundedBorder)
.font(.custom("Chalkduster", size: 15))
.disableAutocorrection(true)
TextField(
"Last Name",
text: $LastName
).textFieldStyle(.roundedBorder)
.font(.custom("Chalkduster", size: 15))
.disableAutocorrection(true)
}
.textFieldStyle(.roundedBorder)
VStack
{
TextField("Select Clinician's Name", text:$choiceMade)
.textFieldStyle(.roundedBorder)
.font(.custom("Chalkduster", size: 15))
Menu
{
Button(action: {choiceMade = "LC Amanda Anderson"},label: {Text("LC Amanda Anderson")})
Button(action: {choiceMade = "Dr. Anthony Franklin"},label: {Text("Dr. Anthony Franklin")})
Button(action: {choiceMade = "LC Elsie Burgos-Carillo"},label: {Text("LC Elsie Burgos-Carrillo")})
Button(action: {choiceMade = "Ingrid Urbaez"},label: {Text("Ingrid Urbaez")})
Button(action: {choiceMade = "LC Kelly Allen"},label: {Text("LC Kelly Allen")})
Button(action: {choiceMade = "LC Kimberly Galloway"},label: {Text("LC Kimberly Galloway")})
Button(action: {choiceMade = "Dr. Michael Grove"},label: {Text("Dr. Michael Grove")})
Button(action: {choiceMade = "LC Selam Kebede"},label: {Text("LC Selam Kebede")})
Button(action: {choiceMade = "LC Susan Savelli"},label: {Text("LC Susan Savelli")})
Button(action: {choiceMade = "Do not know"},label: {Text("Do not know")})
}
label:
{
Label(title: {Text("(choiceMade)").position(x:75,y:0)}, icon: {Image(systemName:"plus")})
}
if (choiceMade == "LC Amanda Anderson")
{
Text("You have an appointment with LC Amanda Anderson").font(.custom("Chalkduster", size: 15))
}
if (choiceMade == "Dr. Anthony Franklin")
{
Text("You have an appointment with Dr. Anthony Franklin").font(.custom("Chalkduster", size: 15))
}
if(choiceMade == "LC Elsie Burgos-Carrillo")
{
Text("You have an appointment with LC Elsie Burgos Carrillo").font(.custom("Chalkduster", size: 30))
}
if (choiceMade == "Ingrid Urbaez")
{
Text("You have an appointment with Ingrid Urbaez").font(.custom("Chalkduster", size: 15))
}
if (choiceMade == "LC Kelly Allen")
{
Text("You have an appointment with LC Kelly Allen").font(.custom("Chalkduster", size: 15))
}
if(choiceMade == "LC Kimberly Galloway")
{
Text("You have an appointment with LC Kimberly Galloway").font(.custom("Chalkduster", size: 15))
}
if (choiceMade == "Dr. Michael Grove")
{
Text("You have an appointment with Dr. Michael Grove").font(.custom("Chalkduster", size: 15))
}
if (choiceMade == "LC Selam Kebede")
{
Text("You have an appointment with LC Selam Kebede").font(.custom("Chalkduster", size: 15))
}
if(choiceMade == "LC Susan Savelli")
{
Text("You have an appointment with LC Susan Savelli").font(.custom("Chalkduster", size: 15))
}
if(choiceMade == "Do not know")
{
Text("Please take a seat while we get the information for you.").font(.custom("Chalkduster", size: 15))
}
}
VStack
{
TextField("Select Reason for Visit", text:$choiceMade2)
.textFieldStyle(.roundedBorder)
.font(.custom("Chalkduster", size: 15))
Menu
{
Button(action: {choiceMade2 = "Counselling"},label: {Text("Counselling")})
Button(action: {choiceMade2 = "Court Ordered Evaluation"},label: {Text("Court Ordered Evaluation")})
Button(action: {choiceMade2 = "Case Management"},label: {Text("Case Management")})
Button(action: {choiceMade2 = "Informational Resources"},label: {Text("Informational Resources")})
Button(action: {choiceMade2 = "Crisis"},label: {Text("Crisis")})
Button(action: {choiceMade2 = "Do not know"},label: {Text("Do not know")})
}
label:
{
Label(title: {Text("(choiceMade2)").position(x:75,y:0)}, icon: {Image(systemName:"plus")})
}
if (choiceMade2 == "Counselling")
{
Text("You are here for Counselling").font(.custom("Chalkduster", size: 15))
}
if(choiceMade2 == "Court Ordered Evaluation")
{
Text("You are here for Court Ordered Evaluation").font(.custom("Chalkduster", size: 15))
}
if (choiceMade2 == "Case Management")
{
Text("You are here for Case Management").font(.custom("Chalkduster", size: 15))
}
if(choiceMade2 == "Informational Resources")
{
Text("You are here for Informational Resources").font(.custom("Chalkduster", size: 15))
}
if(choiceMade2 == "Crisis")
{
Text("How can we assist you today?").font(.custom("Chalkduster", size: 15))
}
if(choiceMade2 == "Do not know")
{
Text("Please take a seat while we check how we can help you today.").font(.custom("Chalkduster", size: 15))
}
}
.frame(maxWidth: /*@START_MENU_TOKEN@*/.infinity/*@END_MENU_TOKEN@*/, alignment: .leading)
.overlay(alignment: .topTrailing)
{
Button
{
// To Do: Handle Adult Logic
}
label:
{
Image(systemName: "star")
.font(.largeTitle)
.symbolVariant(/*@START_MENU_TOKEN@*/.fill/*@END_MENU_TOKEN@*/)
.foregroundColor(.gray.opacity(0.3))
}
.buttonStyle(.plain)
}
HStack {
Spacer()
Button("Save") {
//button action code
}
.buttonStyle(.borderless) // <-- add this line
//or pre-iOS15: .buttonStyle(BorderlessButtonStyle())
Spacer()
Button("Add") {
//button action code
}
.buttonStyle(.borderless) // <-- add this line
//or pre-iOS15: .buttonStyle(BorderlessButtonStyle())
Spacer()
}
}
.navigationTitle("Registrations")
}
}
} #Preview
{
NavigationStack
{ RegistrationRowView()
}
}
Bibin Mathew is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.