ios 为什么整个表单在SwiftUI中充当按钮?

68bkxrlz  于 2023-04-13  发布在  iOS
关注(0)|答案(1)|浏览(127)

为什么整个表单在SwiftUI中充当按钮?

Form {
    VStack {
        Spacer()
        HStack {
            Text("해야 할 일 : ")
            TextField("해야 할 일", text: $addList.name)
        }
        Divider()
        HStack {
            Text("추가 설명 : ")
            TextField("추가 설명", text: $addList.explanation)
        }
        .padding(.vertical)
        Divider()
        Button("추가") {
            toDoList.append(addList)
            addList = ToDoModel(name: "", explanation: "")
            isAdd = true
        }
            .padding(5)
            .background(RoundedRectangle(cornerRadius: 5).stroke(Color.blue, lineWidth: 1))
            .frame(maxWidth: .infinity, alignment: .trailing)
            .alert(isPresented: $isAdd, content: { Alert(
                title: Text("추가 완료"),
                primaryButton: .default(Text("OK")),
                secondaryButton: .cancel(Text("취소"), action: { self.presentationMode.wrappedValue.dismiss() })
            )})
    }
    .padding()
}

htzpubme

htzpubme1#

我认为这是因为它都在一个VStack中。你把这些都放在一个Form {}中?

相关问题