UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

SOLVED: Automatically shuffles views, SwiftUI and Core Data

Forums > SwiftUI

From a List of "Checklists" with navigation links, push to what I call "Checklist Execution View."

In this execution view, user can create a new Checklist. When created, the app shuffles back from the Execution View to the List and then returns to the Execution View.

An error appears in the console: Warning once only: UITableView was told to layout its visible cells and other contents without being in the view hierarchy (the table view or one of its superviews has not been added to a window).

I tried dismissing the Execution View as the first step in the create button, but had no effect.

{
  self.presentationMode.wrappedValue.dismiss()
  self.createModChecklist(checklist: self.checklist)
 }

How can I avoid this undesired behavior?

2      

hi,

you're not the first to see this issue. it's a recurring problem with basically a "don't worry about it right now" answer. for example, see this forum thread marked "SOLVED: Problems with TabView".

hope that helps,

DMG

2      

DMG,

Thanks for sharing. I saw that link and a few on stackoverflow.

But I'm seeing weird behavior in addition to the warning. I'm happy to accept a warning, but the shuffling of views is unsatisfactory. Since I don't have to remain on my Execution View after commanding the create, I was hoping there would be a way to avoid the situation.

I thought maybe dismissing the ExecutionView after creating would fix it, but I can't get that to happen..

PS: How's your shopping list app coming?

2      

hi Daniel,

sorry, i think i read your question mostly about the warning, and without much code to go on, could not quite picture the real problem you were describing.

but i am sure i have seen the behaviour of returning to a previous view, only then to be pushed back to where you left. in one case, i think i had multiple transitions that would go 2 or 3 times by themselves.

i haven't seen this recently, but i think anytime i saw it, especially when returning to a list, i think it was associated with either proper use of Identifiable or id:\.self in the List/ForEach construct, especially if the parent view was maintaining an @State array of the items.

it would be useful to see how you manage data here.

and thanks for asking about my ShoppingList project. it gets better, i spend far too much time on it, but i have solved some problems and learned a lot. in particular, since i began managing CoreData arrays just with @FetchRequest (rather than doing an explicit fetch and then putting the returned values into a @State array), i have not seen the type of behaviour you talked about.

hope that helps,

DMG

2      

I found a workaround...since I didn't mind if the user ended up at the Checklist page, I used the DispatchQueue

{
    self.presentationMode.wrappedValue.dismiss()
    DispatchQueue.main.async {
        self.createModChecklist(checklist: self.checklist)
     }
}

2      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.