如何删除swiftUI列表上的切换下拉菜单

fd3cxomn  于 2022-11-21  发布在  Swift
关注(0)|答案(2)|浏览(128)

我在列表swiftUI上遇到问题,我想删除切换下拉菜单(黑色圆圈),但不禁用切换功能,因此当视图首次加载

时,名称列表(蓝线)出现
这是我的代码,也许它能帮我解决问题

struct IphoneProfileView: View {
    @StateObject var companyViewModel = CompanyViewModel()
    @StateObject var profileViewModel = ProfileViewModel()
    @ObservedObject var employeeListViewModel = EmployeeListViewModel()
    @ObservedObject var role: RoleService = .shared
    var company: Company?
    @State var companyName = ""
    @State var editModeIphone: EditMode = .inactive {
        didSet {
            if editModeIphone.isEditing {
                profileViewModel.isPinHidden = false
            } else {
                profileViewModel.isPinHidden = true
            }
        }
    }
    var body: some View {
        VStack {
            List {
                Section(header: CompanyProfileHeader()) {
                    if editModeIphone.isEditing {
                        CompanyInfoNameTextField(
                            placeholder: "Company Inc.",
                            text: $profileViewModel.company.name
                        )
                        CompanyInfoTextField(
                            title: "Owner PIN",
                            placeholder: "1234",
                            text: $profileViewModel.company.ownerPin
                        )
                    }
                    ReviewPolicy()
                }
                Section(header: EmployeeListHeader()) {
                    ForEach(employeeListViewModel.employees) { employee in
                        EmployeeRow(employee: employee)
                    }
                    .onDelete(perform: employeeListViewModel.delete)
                    .onAppear {
                        UITableView.appearance().separatorStyle = .singleLine
                    }
                }
            }
        }
        .toolbar {
            EditButton()
        }
        .navigationBarTitle("Profile", displayMode: .inline)
        .environment(\.editMode, $editModeIphone)
        .onAppear {
            UITableView.appearance().separatorStyle = .none
        }
    }
}
c9qzyr3d

c9qzyr3d1#

你可以试着在List上添加.listStyle(GroupedListStyle()),类似这样:

List {
            Section(header: CompanyProfileHeader()) {
                if editModeIphone.isEditing {
                    CompanyInfoNameTextField(
                        placeholder: "Company Inc.",
                        text: $profileViewModel.company.name
                    )
                    CompanyInfoTextField(
                        title: "Owner PIN",
                        placeholder: "1234",
                        text: $profileViewModel.company.ownerPin
                    )
                }
                ReviewPolicy()
            }
            Section(header: EmployeeListHeader()) {
                ForEach(employeeListViewModel.employees) { employee in
                    EmployeeRow(employee: employee)
                }
                .onDelete(perform: employeeListViewModel.delete)
                .onAppear {
                    UITableView.appearance().separatorStyle = .singleLine
                }
            }
        }.listStyle(GroupedListStyle())
nnvyjq4y

nnvyjq4y2#

很奇怪,我的诀窍是这样使用list修饰符:

.listStyle(.insetGrouped)

(使用iOS 16.1和Xcode 14.1)

相关问题