我在列表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
}
}
}
2条答案
按热度按时间c9qzyr3d1#
你可以试着在List上添加.listStyle(GroupedListStyle()),类似这样:
nnvyjq4y2#
很奇怪,我的诀窍是这样使用list修饰符:
(使用iOS 16.1和Xcode 14.1)