如何删除swiftUI列表上的切换下拉列表
Posted
技术标签:
【中文标题】如何删除swiftUI列表上的切换下拉列表【英文标题】:How to remove toggle drop down on swiftUI list 【发布时间】:2021-08-19 12:03:03 【问题描述】:我在列表 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
【问题讨论】:
如果您希望您的问题得到解答,您需要让专家尽快获得具有可重现问题的工作样本。完美地,我应该将您的代码粘贴到我的示例项目中,并在我运行它时尽快看到问题。请添加[最小可重现示例] @Philip 对不起,我忘了把我的代码放进去,我已经更新了我的问题,希望你能帮忙 @vandettadyckies 尝试简化代码 - 将其放入项目中不会运行。 【参考方案1】:您可以尝试在列表中添加 .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())
【讨论】:
以上是关于如何删除swiftUI列表上的切换下拉列表的主要内容,如果未能解决你的问题,请参考以下文章
SwiftUI - 列表编辑模式 - 如何更改删除按钮标题?
如何以编程方式从 SwiftUI 列表中删除行并刷新列表视图?