Модель: < Br />
Код: Выделить всё
struct Item: Identifiable {
var id: String {
UUID().uuidString
}
var name: String?
var addr: String?
init(name: String? = nil, addr: String? = nil) {
self.name = name
self.addr = addr
}
}
< /code>
Просмотр: < /p>
struct ContentView: View {
let arr = [
Item(name: "Roman", addr: "Address of Roman"),
Item(name: "Alexa", addr: "Address of Alexa"),
]
@State private var selection: Item?
var body: some View {
VStack {
List {
ForEach(arr) { item in
Text(item.name!)
.id(item.name!)
.onTapGesture {
selection = item
print("selection: \(item.name ?? "")")
}
.popover(item: $selection) { item in
Text(item.addr ?? "")
}
}
}
}
}
Почему поповер не работает, как ожидалось с Список элементов?
Это ошибка в Swiftui?
Подробнее здесь: https://stackoverflow.com/questions/793 ... in-swiftui
Мобильная версия