【发布时间】:2020-03-13 09:39:15
【问题描述】:
我在 SwiftUI 中有一个带有标签的 TabView。当我从一个 FirstView 滚动列表并点击另一个选项卡并切换回 FirstView 时,我在 FirstView 中的列表会自动重绘并滚动到顶部。如何解决这个问题。
这是第一视图
var body: some View {
NavigationView {
List {
ForEach(feed) { game in
FeedCardItem(gameModel: game)
.frame(width: UIScreen.main.bounds.width - 30, height: 400)
}
}
.navigationBarTitle(Text("Новое сегодня"))
}
}
这是 TabView 实现
TabView (selection: $currentTab) {
FeedView().tabItem {
Image(systemName: currentTab == 0 ? "house.fill" : "house")
.renderingMode(.original)
.imageScale(.large)
}.tag(0)
RecommendationsView().tabItem {
Image(systemName: currentTab == 1 ? "gamecontroller.fill" : "gamecontroller")
.renderingMode(.original)
.imageScale(.large)
}.tag(1)
SearchView().tabItem {
Image(systemName: currentTab == 2 ? "flame.fill" : "flame")
.renderingMode(.original)
.imageScale(.large)
}.tag(2)
NotificationsView().tabItem {
Image(systemName: currentTab == 3 ? "bell.fill" : "bell")
.renderingMode(.original)
.imageScale(.large)
}.tag(3)
ProfileView().tabItem {
Image(systemName: currentTab == 4 ? "person.fill" : "person")
.renderingMode(.original)
.imageScale(.large)
}.tag(4)
}.edgesIgnoringSafeArea(.top)
}
【问题讨论】:
-
提供一些可以运行和调试的最小代码。这将有助于提供快速答案。
-
@FelixMarianayagam 添加了
-
应该可以。
标签: swiftui swiftui-list