Saturday, July 27, 2024
HomeiOS Developmentios - Easy methods to stop a selectable Listing from being up...

ios – Easy methods to stop a selectable Listing from being up to date when a affirmation dialog seems?


Let’s us a selectable Listing as follows:

import SwiftUI

struct ContentView: View {
    @State personal var parts: Set<UUID> = [.init(), .init(), .init()]
    @State personal var choice: Set<UUID> = []
    @State personal var isConfirmationDialogPresented: Bool = false
    
    var physique: some View {
        NavigationStack {
            Listing(
                parts.sorted(),
                id: .self,
                choice: $choice,
                rowContent: { Textual content(String(describing: $0)).lineLimit(1) }
            )
            .toolbar {
                ToolbarItem(placement: .topBarTrailing) {
                    EditButton()
                }
                ToolbarItem(placement: .bottomBar) {
                    Button(
                        "Delete (choice.depend) aspect(s)",
                        position: .harmful,
                        motion: { isConfirmationDialogPresented = true }
                    )
                    .disabled(choice.isEmpty)
                    .confirmationDialog(
                        "Delete (choice.depend) parts(s)",
                        isPresented: $isConfirmationDialogPresented,
                        actions: {
                            Button("Delete (choice.depend) aspect(s)", motion: {
                                parts = parts.subtracting(choice)
                            })
                        }
                    )
                }
            }
        }
    }
}

When tapping the Button to show the affirmation dialog, the selectable Listing is reset (all chosen rows develop into unselected, i.e. the choice worth turns into an empty Set). Easy methods to stop this?

Notice: shifting the .confirmationDialog to Listing causes the identical conduct.

Examined with Xcode 16 beta 4 • iOS 18.



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments