我在为一些看起来很简单的事情而苦苦挣扎. 我有一个带有导航链接的视图,因为它不是我的应用程序的主要视图.在此视图中,我有一些发送到此视图的链接,但具有不同的数据.我想嵌套这些链接,但现在我在顶部收到了双选项卡视图.我怎样才能改变这一点?我知道我需要切换第二个视图上的导航栏,但我的第二个视图实际上是同一个视图,但具有不同的数据.
以下是代码
/// ContentView
struct MatchListView: View {
var namespace: Namespace.ID
@ObservedObject var dataViewModel = DataViewModel()
@State private var selectedMatchID: Int?
@State private var selectedDayIndex: Int = 0
@State private var headerHeight: CGFloat = 0
@State private var didFinishFirst = false
var body: some View {
ForEach(data.leagues, id: \.id) { league in
VStack {
leagueHeader(league: league)
ForEach(league.matches, id: \.id) { match in
matchRow(match: match, namespace: namespace)
}
}
.foregroundStyle(Color.textAccent)
.background(Color.bgSecondaryAccent)
.cornerRadius(10)
}
}
}
func matchRow(match: Match, namespace: Namespace.ID) -> some View {
NavigationLink(destination: MatchDetailsView(namespace: namespace, matchID: match.id, homeTeamName: match.home.name, awayTeamName: match.away.name)) {
Text("go to match \(match.id)")
}
}
/// MatchDetails View
struct MatchDetailsView: View {
NavigationView {
List {
ScrollView(showsIndicators: false) {
HighlightsView(matchViewModel: matchViewModel)
MOTMView(matchViewModel: matchViewModel)
EventsView(matchViewModel: matchViewModel)
MatchStats(matchViewModel: matchViewModel)
MatchTopPlayers(matchViewModel: matchViewModel)
TeamFormView(matchViewModel: matchViewModel)
}
}
}
.toolbar {
ShareLink(item: URL(string: "https://maykmayk.github.io/Balun/#/match-details/\(matchID)")!) {
Label("", systemImage: "square.and.arrow.up")
}
Button {
// action
} label: {
Image(systemName: "bell")
}
Button {
// action
} label: {
Image(systemName: "star")
}
}
.toolbarRole(.editor)
.tint(Color(.textAccent))
}
/// TeamformView
struct TeamFormView: View {
var body: some View {
NavigationLink(destination: MatchDetailsView(namespace: namespace, matchID: getMatchID(from: match.linkToMatch ?? ""), homeTeamName: match.home?.name ?? "", awayTeamName: match.away?.name ?? "")) {
Text(match.score ?? "")
.foregroundColor(.white)
.font(.system(size: 14, weight: .medium))
.padding(.horizontal, 5)
.padding(.vertical, 2.5)
.background(
match.resultString == "W" ? Color.greenAccent :
match.resultString == "L" ? Color.redAccent :
match.resultString == "D" ? Color.gray.opacity(0.5) :
Color.black
)
.clipShape(RoundedRectangle(cornerRadius: 6, style: .continuous))
}
}
}
我的预览: https://ibb.co/gRHcDSb个 我想要的是: https://ibb.co/W6ysFYn