0

When I run this code, the list is visible behind the tab bar created by the TabView. If I comment out the Image, everything is ok.

How do I make sure the list is not visible behind the tab bar?

struct MainView: View {
    var body: some View {
        TabView {
             ScheduleView()
                 .tabItem { Label ("Schedule", systemImage: "calendar") }
             ScheduleView()
                 .tabItem { Label ("Schedule", systemImage: "calendar") }
             ScheduleView()
                 .tabItem { Label ("Schedule", systemImage: "calendar") }
    
        
        }
    }
}

struct ScheduleView: View {
    @State var category = Categories.mixed
    
    var body: some View {
        VStack {
            HStack(alignment: .top) {
                Image("svrge-logo")
                    .resizable()
                    .scaledToFit()
                    .frame(height: 80)
                    .padding(.leading)
                Spacer()
                VStack(alignment: .trailing) {
                    Text ("Ver: 1.0")
                    Text ("nn matches")
                }
                .padding(.horizontal)
                .font(.caption)
            }
            
            Picker ("Gender", selection: $category) {
                ForEach(Categories.allCases) {
                    Text ($0.id).tag($0)
                }
            }
            .pickerStyle(SegmentedPickerStyle())
            
            List(filteredMatches(for: category)) { match in
                VStack {
                    HStack {
                        Text (match.matchNumber)
                        Spacer()
                        Text (match.date.toString(withFormat: "dd.MM.yyyy @ HH:mm"))
                    }
                    HStack {
                        Text (match.homeTeamName)
                        Spacer()
                        Text (match.awayTeamName)
                    }
                }
                
            }
            .listStyle(.plain)
        }
    }
}

enum Categories: String, Codable, CaseIterable, Identifiable {
    case womens
    case mens
    case mixed
    
    var id: String {
        return self.rawValue.capitalized
    }
}

var allMatches: [MatchInfo] = MatchInfo.data

func filteredMatches(for category: Categories) -> [MatchInfo] {
    return allMatches
        .filter { $0.category == category }
        .sorted()
}

let teamNames1 = (0...30).map{"Team \($0)"}
let teamNames2 = (31...60).map{"Team \($0)"}

struct MatchInfo: Identifiable, Comparable {
    var id: String { "\(season)-\(matchNumber)" }
    
    var season = "2022-2023"
    var matchNumber: String
    var date: Date = Date()

    var location = "Some Gym"
    var category:Categories = Categories.allCases.randomElement()!
    
    var homeTeamName = teamNames1.randomElement()!
    var awayTeamName = teamNames2.randomElement()!
    
    static func < (lhs: MatchInfo, rhs: MatchInfo) -> Bool {
        return lhs.date.timeIntervalSince(rhs.date) < 0
    }
    
    static func == (lhs: MatchInfo, rhs: MatchInfo) -> Bool {
        return lhs.date == rhs.date
    }
}
2
  • Please update your question with minimal relevant code (as text) in your question that demonstrates the issue. Perhaps include relevant screenshots showing the correct result and the incorrect result. Commented Mar 14, 2023 at 0:49
  • please read my post completely. Commented Mar 14, 2023 at 8:30

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.