1

使用以下代码,在长按时重新排序列表有效,但仅在 iPad 上,在 iPhone 上长按不起作用。我怎样才能让它也能在 iPhone 上运行?

var body: some View {
        NavigationView {
            List {
                ForEach(objects, id: \.firstName) { object in
                    Text("\(object.firstName) \(object.lastName)")
                }
                .onMove(perform: move)
            }
        }
    }

    func move(from source: IndexSet, to destination: Int) {
        objects.move(fromOffsets: source, toOffset: destination)
    }
4

1 回答 1

0

你可以试试这个:

struct ContentView : View {

    @State var isEditMode: EditMode = .active


    var body: some View {
        NavigationView {
            List {
                ForEach(objects, id: \.self) { object in
                    Text("\(object)")
                }
                .onMove(perform: move)
            }.environment(\.editMode, self.$isEditMode)
        }
    }
于 2019-11-17T09:54:58.877 回答