Вот минимальный воспроизводимый пример:
Код: Выделить всё
import SwiftUI
struct ContentView: View {
@State var array = ["One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten"]
@State var selectedItem: Int? = nil
var body: some View {
VStack {
Text("Snork!")
List(Array(array.enumerated()), id: \.offset, selection: $selectedItem) { index, item in
Text(item).tag(index) // .tag suggested in comment
}
.padding()
}
}
}
#Preview {
ContentView()
}
Если вы запустите его на iOS 15.x список игнорирует нажатия. Элементы нельзя выбрать.
Я все еще новичок в SwiftUI. Что мне не хватает?
Подробнее здесь: https://stackoverflow.com/questions/792 ... -in-ios-15
Мобильная версия