'How to scroll two lists synchronously in swiftui
I have two related lists side-by-side. I want to scroll any one of the lists, and the other one can scroll synchronously. Is there any way to achieve the effect? Any help will be appreciated.
struct ScrollTwoListsSynchronously: View {
let dataSet = [1,2,3,4,5]
var body: some View {
HStack{
List{
ForEach(dataSet,id:\.self){data in
Text(String(data))
}
}
.listStyle(PlainListStyle())
List{
ForEach(dataSet,id:\.self){data in
Text(String(data))
}
}
.listStyle(PlainListStyle())
}
}
}
Supplementary information:
Seeing the comments and answers below, I realize that my problem description is not comprehensive enough. Sorry!
I want to show some data in two columns according the layout need. The left one shows the odd numbered data(NO1\NO3...), and the right one shows the even numbered data(NO2\NO4...). The 2 columns may have the same number of lines, if not, the left column has 1 more line than right.
Putting all of the data into a single list or a two-column grid seems a good choice. But I also want to use the multiple selection function that comes with the list, in order to select some data items. If two data items are in the same row of the list. I'm afraid I cannot choose only one of them. Based on this consideration, I wonder if I could use two lists to show the two column data synchronously to keep NO1 & NO2(NO3 & NO4, NO5 & NO6,...) always in the same line. If feasible, I can directly use the multi-select function of list to select any items, without creating a custom function.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
