This simple test case should scroll to the last line of a list after appending a new item. The code works fine with iOS 15 but cause a runtime error on iOS 16.
import SwiftUI
struct ScrollListView: View {
@State private var data: [String] = []
var body: some View {
VStack {
Button(action: {
data.append("ScrollItem #\(data.count+1)")
}) {
Label("Add Row", systemImage: "plus")
}
.buttonStyle(.borderedProminent)
ScrollViewReader { proxy in
List(0..<data.count, id: \.self) { index in
Text(data[index]).id(index)
}
.listStyle(.grouped)
.navigationTitle("ScrollList Test")
.onChange(of: data.count) { _ in
proxy.scrollTo(data.count-1)
}
}
}
.onAppear() {
for _ in 0..<30 {
data.append("ScrollItem #\(data.count+1)")
}
}
}
}
Tested with Xcode 14 and Xcode 14.1 beta 2 on iOS 15, iOS 16 and iOS 16.1 beta. Works only on iOS 15 as expected.
Error message on line proxy.scrollTo(data.count-1):
0x0000000100fb8050 in closure #2 in closure #3 in closure #1 in ScrollListView.body.getter at /…/TestApp/Features/Scrollview/ScrollTestView.swift:29
I have made a bug report to Apple but if anyone knows of a work around i would be happy.
Post
Replies
Boosts
Views
Activity
This simple test code works fine in iOS 16 Beta 3:
struct ContentView: View {
enum Route: Hashable {
case one
case two
}
var body: some View {
NavigationSplitView {
NavigationLink("Target One", value: Route.one)
NavigationLink("Target Two", value: Route.two)
} detail: {
NavigationStack {
Text("Home")
}
.navigationDestination(for: Route.self) { route in
switch route {
case .one:
Text("Target for Route One")
case .two:
Text("Target for Route Two")
}
}
}
}
}
But in Beta 4 and Xcode 14 Beta 4 I got this error if I click on a NavigationLink:
A NavigationLink is presenting a value of type “Route” but there is no matching navigation destination visible from the location of the link. The link cannot be activated.
Is there something wrong with this code or is it a bug in beta 4? Anyone have ideas how to fix this?