Learn Courses My Dashboard

datePicker Problems

I’m having problems with being able to change a date on a view. The data is stored in CoreData

On one view, PersonAddNew, I have a datePicker to select the person’s birthdate, and it works fine.

On another view, PersonView, when I put in a datePicker, the view does not display at all. When I comment out the datePicker the view displays normally. Below is the code with the datePicker not commented out.

@State var title: String = ""
@State var firstName: String = ""
@State var middleName: String = ""
@State var lastName: String = ""
@State var birthDate = Date()

    GeometryReader { geo in
        //MARK: Enter view
            Section(header: HStack {
                Button(action: cancelData) {
                Button(action: setEditMode) {
                Button(action: deletePerson) {
                VStack(alignment: .leading){
                    TextField(oldPerson.title ?? "Enter Title", text: $title)
                    TextField(oldPerson.firstName ?? "Enter First Name", text: $firstName)
                    TextField(oldPerson.middleName ?? "Enter Middle Name", text: $middleName)
                    TextField(oldPerson.lastName ?? "Enter Last Name", text: $lastName)
                    DatePicker("", selection: $birthDate, displayedComponents: .date)

Take out the VStack. You don’t need that since all the items are inside a Form.

It worked, thanks.