|
To summarise, my problem is this: I want to take an array of items and display them in a list, with the items being displayed in different sections of the list depending on certain properties of the items. I can achieve this by creating the sections one by one, but when I try to simplify the process with a Here's a simplified example which illustrates the problem: First, I set up a
Then for the main view:
This works perfectly. I see a list with two sections ("Not fresh" and "Fresh"), and a new row containing "Potato" is added to the "Fresh" section every time I press the button. However, when I try to simplify the code using a
With this modificaiton, the code will compile and the items are displayed in the correct sections, but when I click the button to "Add a fresh potato", nothing appears in the list. From a little experimenting with a Tab View, it seems that the button is adding a new vegetable item to I would be hugely grateful if anyone could explain why the first option works but the second does not! |
|
hi, i've played around with this issue recently ... it drove me crazy for awhile, and still does ... and the best i could come up with is to first, make Vegetable Hashable (nothing special to do here other than write so the following code seems to work for me:
i do get a warning on the console ("Warning once only: UITableView was told to layout its visible cells ..."), but the code seems to work fine. this could well be one of those SwiftUI things that will get fixed real soon, and one of those messages many folks seem to tell you to ignore. i'm hoping for an easier way to do this in the next version of SwiftUI. hope that helps, DMG |
|
This works perfectly - thank you so much for your help! I've now got this working in both the simplified version and my original project. As you say, hopefully the issue will be fixed soon, but in the meantime this does the job nicely. Thanks again! Alasdair |
SPONSORED Still waiting on your CI build? Speed it up ~3x with Blaze - change one line, pay less, keep your existing GitHub workflows. First 25 HWS readers to use code HACKING at checkout get 50% off the first year. Try it now for free!
Sponsor Hacking with Swift and reach the world's largest Swift community!
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.
Link copied to your pasteboard.