Reputation: 4936
I am new in Swift
, please help me a hand
The first question is Can use TabView
inside a TabView
?
If it can be, I got an issue related to List
, items inside List
is highlighted when I tap into another place
// This tab will have many pages and can swap left/right to change tabs
struct Tab1: View {
var body: some View {
TabView(selection: $otherSelected) {
SubOfTab1()
.tag("tag1")
... other tabs
}
.tabViewStyle(PageTabViewStyle(indexDisplayMode: .never))
}
}
// This tabview will display tab item as bottom
struct ContentView: View {
var body: some View {
TabView(selection: $selected) {
var body: some View {
Tab1()
.tag("tagParent1")
... other tabs
}
}
}
}
struct SubOfTab1: View {
VStack {
Text("Try to tab this text") ------> Try to tab this and all list items below is hightlighted??? why???
.frame(height: 100)
List() {
Text("XX")
Text("XX")
Text("XX")
Text("XX")
...
}
}
}
First run
Tapped to the text above, all items in List
are highlighted
??
Upvotes: 1
Views: 759
Reputation: 76
I had similar issue with List of .plain style inside a TabView, tapping outside list resulted to selection all visible list items.
Setting .listRowBackground() of list cell fixed it.
In your case:
List() {
Text("XX")
.listRowBackground(Color.black)
Text("XX")
.listRowBackground(Color.black)
Text("XX")
.listRowBackground(Color.black)
Text("XX")
.listRowBackground(Color.black)
...
}
Upvotes: 2