Same issue did try all the things but it's not working! So annoying we cant test our application on our device
Post
Replies
Boosts
Views
Activity
Finally, in iPadOS 17 beta 5, I tested it and it worked! Thanks for resolving this bug that had been causing me frustration for the past 2 years. I now realize it was not my fault. I believe it's important to extend this fix to older versions of iPadOS as well since 3-column apps are completely unusable on those versions.
But what about adding multiple items at the top of the list? I did that and the result was strange, when I start scrolling it couldn't scroll properly. We are developing something really important and we need that ability but Swiftui has a problem with it!
struct SwiftUIView: View {
@State var data: [String] = (0 ..< 25).map { String($0) }
@State var dataID: String?
var body: some View {
ScrollView {
VStack {
Text("Header")
LazyVStack {
ForEach(data, id: \.self) { item in
Color.red
.frame(width: 100, height: 100)
.overlay {
Text("\(item)")
.padding()
.background()
}
}
}
.scrollTargetLayout()
}
}
.scrollPosition(id: $dataID)
.safeAreaInset(edge: .bottom) {
HStack {
Text("\(Text("Scrolled").bold()) \(dataIDText)")
Spacer()
Button {
dataID = data.first
} label: {
Label("Top", systemImage: "arrow.up")
}
Button {
dataID = data.last
} label: {
Label("Bottom", systemImage: "arrow.down")
}
Menu {
Button("Batch Prepend") {
let newDatas = (data.count ..< data.count + 6).map{"New Data \($0)"}
newDatas.forEach { data in
self.data.insert(data, at: 0)
}
// data.insert(contentsOf: newDatas, at: 0) // Does not have any difference.
}
Button("Prepend") {
let next = "New Data 1"
data.insert(next, at: 0)
}
Button("Append") {
let next = String(data.count)
data.append(next)
}
Button("Remove First") {
data.removeFirst()
}
Button("Remove Last") {
data.removeLast()
}
} label: {
Label("More", systemImage: "ellipsis.circle")
}
}
}
}
var dataIDText: String {
dataID.map(String.init(describing:)) ?? "None"
}
}
I don't know what I should do to accept it as a bug. I reported it here and in the Bug Reporter app, but there is no hope of fixing this bug.
After 4 months of waiting again no response from the Apple developer! This is a huge bug in iPadOs and even the newest version of the sample app that Apple provided has exactly the same bug. It's impossible to make an app for iPadOS to persist data with NavigationSplitView after going to the home screen.
I fixed the problem just by removing all unnecessary views around the List and just putting the pure view at the root of the view. Also, you need to be cautious about ZStack and so on. My piece of advice is that, commenting all the views and modifiers and then step by step uncomment the views until you can find the root of the problem.
With this link, you can realize what I'm talking about.
https://youtu.be/WdPHHJvNcLQ
I've found a solution for that but I truly believe that it's a SwiftUI bug.
You must move the navigation link to the upper parent and view.
import SwiftUI
struct ContentView: View {
@State
var shownextPage = false
var body: some View {
NavigationView{
ZStack{
TabView{
Tab1(shownextPage: $shownextPage)
.tabItem({Text("tab1")})
Tab2()
.tabItem({Text("tab2")})
}
NavigationLink(destination: SecondView(), isActive: $shownextPage) {
EmptyView()
}
}
.navigationViewStyle(.stack)
}
}
}
struct Tab1: View {
@Binding
var shownextPage:Bool
var body: some View {
ZStack{
Button ("Next Page"){
shownextPage = true
}
}
}
}
struct Tab2: View {
var body: some View {
Text("Tab 2 detail")
}
}
struct SecondView: View {
@State
var showSheet:Bool = false
var body: some View {
VStack{
Button {
showSheet = true
} label: {
Text("open Sheet")
.padding()
}
}
.sheet(isPresented: $showSheet, onDismiss: nil) {
Text("hello in sheet")
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
No one can help?