Two Dynamic Sections in UITable with Core Data?


Hello All,

I was wondering how easy/hard it is to make a UITableView that has just two sections and allow the user be able to update/add/edit/ect “each” section independently using Core Data as the backend management of it all. The book gets one section done great, but doesn’t even hint on how to do the same thing with a different section of the same table. I assume this means it is really easy and you just copy almost everything from the first section for your second section with a new Core Data Entity, but then again this might be more difficult then it sounds.

Any advice or gottcha’s to look out for when trying something like this? I can’t believe I couldn’t find one example using Core Data and two sections of a UITableView that the user could add information/edit information to on the web. I assume this has to be some what common?

Thanks for such a great book!


I would say that to implement what you are asking is pretty straight forward, I guess it just comes down to exactly what you were trying to achieve.

Taking the Homepwner project as an example, if you simply wanted to display a section for each asset type then you could:
Use the number of different asset types to determine how many sections would be displayed in the table view, either by returning the number manually, or doing a count on allAssetTypes (preferred way as the user may be allowed to add more asset types)
You would then possibly populate each section using a switch case statement based on each asset type

I am not sure if this quite answers your question at all.



Okay, I think I can manage. I will try to create two sections for the table and when a user adds an entry i will use a switch statement to determine if that should be added to the first section or the second section.

It seems like I wouldn’t have to change the Core Data model that way either. It will just continue to add or delete entries it shouldn’t care which section it is doing it from right?


Yeah, I think using a switch case statement would work, however I haven’t implemented sectioned data myself yet - maybe it’s something I should try now that you have mentioned it.