ios - Use Core Data With UITableView With Sections That Have A Different Number Of Cells -


so have tableview contains sections can possibly hold different amount of cells depending on user input rows detail. trying learn more saving , want make simple app allows user save recipe ingredients. example can have 5 different sections containing 5 different types of food -> banana: amount-2 calories-10 details-slice, apple amount-3 calories-20 details-mash <-. user click done , or recipe name saved , displayed on cell in table view. once user clicks on he/she can see he/she put , can edit if he/she desires. told core data best type of saving.

how save info in organized way. know how save individual cells using core data hard each section can contain unique number of cells , data saved 1 data entry. it's array inside of array inside of array. have feeling have use dictionaries. can't seem structure of data. can or have tips on how should attack this? i'm using swift way.

picture of 1 section of tableview might like:

picture of 1 section of tableview might like.

there's several ways can tackle situation. first solution came mind storing unique array each section want display. e.g. fruit array, vegetable array, etc. if did this, when fetch core data store items in appropriate arrays , similar following within numberofrowsforsection:

switch (section) { case 0:     return fruit.count() case 1:     return vegetable.count() default:     return 0 } 

that switch statement called according whichever section in @ time. if went different route dictionary, instead of returning count of different array, return typedict.objectforkey("fruit") instead.


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -