尽管我遇到了错误,但我正在关注 Paul Hudson 关于程序化导航的文章。
我使用三个简单的视图重新创建了错误。我要做的是从 ContentView -> ChildViewOne -> ChildViewTwo -> ContentView 移动。
我从 ChildViewTwo -> ContentView 收到以下错误:
2021-05-20 15:06:44.346713+1200 Test[7756:137785] [Assert] UIScrollView 不支持多个观察者实现observeScrollView:willEndDraggingWithVelocity:targetContentOffset:unclampedOriginalTarget:。滚动视图 < TtC7SwiftUIP33_BFB370BA5F1BADDC9D83021565761A4925UpdateCoalescingTableView: 0x7fb75a8df000; 基类 = UITableView; 帧 = (0 0; 390 844); clipsToBounds = YES; 手势识别器 = <NSArray: 0x6000016fe730>; 层 = <CALayer: 0x60000181a960>; 内容偏移:{0,-239};内容大小:{390, 169.33333333333334};调整内容插入:{239, 0, 34, 0}; 数据源:< TtGC7SwiftUIP13$7fff56921d2819ListCoreCoordinatorGVS_20SystemListDataSourceOs5Never_GOS_19SelectionManagerBoxS2:0x7fb75980e410>>,新观察者<TtGC7SwiftUI41StyleContextSplitViewNavigationControllerVS_19SidebarStyleContext : 0x7fb758855000>,移除旧的观察者 < TtGC7SwiftUI41StyleContextSplitViewNavigationControllerVS_19SidebarStyleContext : 0x7fb75902ca00>
返回 ContentView 时,我也会获得双重导航。
内容视图
struct ContentView: View {
@State private var isShowingChildOne = false
var body: some View {
NavigationView {
List {
Text("Hello World")
Text("Hello World")
Text("Hello World")
}
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
VStack {
// Programmatic navigation here
NavigationLink(destination: ChildViewOne(), isActive: $isShowingChildOne) { EmptyView() }
Button("Next") {
self.isShowingChildOne = true
}
}
}
}.navigationTitle("ContentView")
}
}
}
ChildViewOne
struct ChildViewOne: View {
var body: some View {
List(0..<5) { item in
NavigationLink(destination: ChildViewTwo()) {
Text("Hello")
}.navigationTitle("Child One")
}
}
}
子视图二
struct ChildViewTwo: View {
@State private var isShowingContentView = false
var body: some View {
Text("Hello")
.navigationTitle("Child Two")
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
VStack {
// Programmatic navigation here
NavigationLink(destination: ContentView(), isActive: $isShowingContentView) { EmptyView() }
Button("Add") {
self.isShowingContentView = true
}
}
}
}
}
}