【发布时间】:2020-06-25 06:14:56
【问题描述】:
我需要 SwiftUI 列表的多行编辑选项
- 我在 NavigationView 中的登录屏幕
- 登录后主屏幕是选项卡 酒吧
- 其中一个选项卡是列表视图(我需要为此编辑选项 列表)
这是我的总代码
第一个屏幕我只有带有文本字段和按钮的简单导航视图。
struct HomeView: View {
@ObservedObject var viewModel = HomeViewModel()
//@State var title = "Home"
var body: some View {
TabView(selection: $viewModel.selectedView) {
TasksView()
.tabItem {
Image(“one”)
Text(“one”)
}.tag(0)
DashboardView()
.tabItem {
Image(“two”)
Text(“two”)
}.tag(1)
NotifcationsView()
.tabItem {
Image(“some”)
Text(“some”)
}.tag(2)
SettingsView()
.tabItem {
Image(“set”)
Text("Se")
}.tag(3)
}
.navigationBarBackButtonHidden(true)
.navigationBarItems(trailing: EditButton())
.navigationBarTitle(Text(viewModel.title) , displayMode: .inline)
}
}
struct TasksView: View {
@ObservedObject var viewModel = TViewModel()
@State var segmentSelection = 0
@State var selection = Set<String>()
// @State var editMode = EditMode.active
var body: some View {
VStack {
Picker(selection: $viewModel.segmentSelection, label: Text("")) {
ForEach(0..<self.viewModel.segments.count) {index in
Text(self.viewModel.segments[index]).tag(index)
}
}.pickerStyle(SegmentedPickerStyle())
.padding(5)
//MyTaskListView()
List (selection: $selection) {
ForEach(viewModel.mt){ t in
//TaskCell(t : task)
Text("Title")
}
.onDelete(perform: viewModel.delete)
}
}.onAppear{
self.viewModel.requestMYTasks()
}
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .topLeading)
}
init() {
UISegmentedControl.appearance().selectedSegmentTintColor = Colors.navBarColor
UISegmentedControl.appearance().setTitleTextAttributes([.foregroundColor: UIColor.white], for: .selected)
UISegmentedControl.appearance().setTitleTextAttributes([.foregroundColor: Colors.navBarColor], for: .normal)
}
}
在保持简单行后,编辑也不起作用
【问题讨论】:
标签: ios swiftui swiftui-list