Reputation: 101
I'm having a problem on list swiftUI I want to remove toggle drop down (black circle), without disabling the function of toggle, so the list of names (blue line) is appear when the views first load
Here's my code, maybe it would help to fix my problem
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
}
}
}
Upvotes: 0
Views: 1177
Reputation: 232
Very odd, what did the trick for me was to use the list modifier like this:
.listStyle(.insetGrouped)
(Using iOS 16.1 and Xcode 14.1)
Upvotes: 2
Reputation: 91
You can try to add the .listStyle(GroupedListStyle()) on the List, something like this:
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())
Upvotes: 0