Я узнал о SwiftUI, и у меня возникают трудности с пониманием List в SwiftUI.
Определение списка приведено ниже.
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
public struct List<SelectionValue, Content> : View where SelectionValue : Hashable, Content : View {
/// Creates a List that supports multiple selection.
///
/// - Parameter selection: A binding to a set that identifies the selected
/// rows.
///
/// - See Also: `View.selectionValue` which gives an identifier to the rows.
///
/// - Note: On iOS and tvOS, you must explicitly put the `List` into Edit
/// Mode for the selection to apply.
@available(watchOS, unavailable)
public init(selection: Binding<Set<SelectionValue>>?, @ViewBuilder content: () -> Content)
/// Creates a List that supports optional single selection.
///
/// - Parameter selection: A binding to the optionally selected row.
///
/// - See Also: `View.selectionValue` which gives an identifier to the rows.
///
/// - Note: On iOS and tvOS, you must explicitly put the `List` into Edit
/// Mode for the selection to apply.
@available(watchOS, unavailable)
public init(selection: Binding<SelectionValue?>?, @ViewBuilder content: () -> Content)
:
:
}
Тогда у меня такой вопрос, как я могу получить Список, который поддерживает множественный / один выбор? Я бы знал, как установить аргументы Binding<Set<SelectionValue>>?
и Binding<Set<SelectionValue>>?
.
. Я прочитал Как можно включить выбор в списке SwiftUI , и у меня есть этот код. Этот код поддерживает множественный выбор.
var demoData = ["Phil Swanson", "Karen Gibbons", "Grant Kilman", "Wanda Green"]
struct ContentView: View {
@State var selectKeeper = Set<String>()
var body: some View {
NavigationView {
List(demoData, id: \.self, selection: $selectKeeper){ name in
Text(name)
}
.navigationBarItems(trailing: EditButton())
.navigationBarTitle(Text("Selection Demo \(selectKeeper.count)"))
}
}
}
Но все еще не могу понять, как я могу установить аргумент «выбор» и тип. Как я могу изменить один список выбора? Что такое Set<String>()
...?
Кто-нибудь объясняет легко понять? У меня был бы простой пример ...
Большое спасибо, Сенсей! Спасибо, что прочитали мой вопрос !!