You need to use item instead of isPresented, which means you trigger the sheet by assigning/updating the selected value, instead of toggling a boolean value.
In code that would be something like this.
struct UpdateStateProperty: View {
var items:[Item] = [Item(name: "Oranges"),
Item(name: "Apples"),
Item(name: "Cookies") ]
@State private var presentView = false
@State private var selectedItem: Item?
var body: some View {
List{
ForEach(items){ item in
HStack{
Text(item.name)
}.onTapGesture {
selectedItem = item
}
}
}
.sheet(item: $selectedItem) { item in
Text("\(item?.name ?? "")")
}
}
}
I haven't tested the above code, just copied yours, but you got the idea.
Post
Replies
Boosts
Views
Activity
Hi 👋
Did you manage to resolve this issue? currently I'm facing the same issue, 2 days and not finding where I'm going wrong? Thanks.