3

In a SwiftUI List that is in Edit mode, each row has a handle at its trailing edge so that the row can be moved up or down in the sequence of rows. In UIKit there is an instance method tableView(_:canMoveRowAt:) which specifies which rows contains those handles and which do not.

I'm seeking the equivalent in SwiftUI. Any ideas?

1 Answer 1

11

You need to use .moveDisabled(condition) modifier, like in below example

    ForEach(items, id: \.self) { item in
        Text(item)
          .moveDisabled(item == "nonmovable item")    // << conditional !!
    }
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you - I never would have found that in all the ViewModifiers listed!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.