I figured out my own solution. Before I share that for the benefit of anyone else who is having this problem, I want to explain why a sheet will not work in this situation, at least not the way I have implemented it.
The key to understanding is to note that the table is actually a loop, looping over the array of channels. When the showingViewSheet State variable is toggled, that kicks off a redraw of the view. The first item in the array is then displayed as a sheet, as it is the first item to be looped. The Dismiss button toggles that state variable again, but it does not stop the redraw, so the loop continues through the array, resulting in the flashing of the other items that I observed (see my comment).
I don’t think I can pull that sheet code out of the inferred loop, so I decided to go with a ZStack instead.Here is the relevant code:
@State private var selectedChannel = blankChannels[0]
var body: some View {
ZStack {
Table(channels, selection: $selection, sortOrder: $sortOrder) {
.
.
.
TableColumn("View/Edit") { channel in
HStack {
Button {
selectedChannel = channel
showingView.toggle()
} label: {
Label("", systemImage: "eye")
}
.
.
.
}
}
}
if(showingView)
{
Color.white.opacity(1.0)
VStack {
ChannelDetailView(channel: selectedChannel)
Spacer()
Button("Dismiss") {
showingView.toggle()
selectedChannel = blankChannels[0]
}
}
.padding()
}
}
}
This worked, showing the info for the channel in which the eye was clicked:
It's not completely optimal, but it will do for this application.
Hope this helps someone else.
Don Carlile
Post
Replies
Boosts
Views
Activity
I looked more carefully at the sheet dismissal. I found that the the reappearance of the sheet after dismissal showed the info for the second row. In fact, when I added another row, I got two reappearances, so the info for all the rows appears quickly. I have no idea why I am getting an iteration over teh entire table rather than the information for the one row which I clicked.