My scenario is that I have three different types of arrays that might or might not contain values. I have 3 sections with section headers for my tableview. I am having trouble finding a solution that would be to dynamically set the sections i.e, if one of my arrays doesn’t have a value then I don’t want to show the section. If 3 arrays have value then show the 3 sections or if any one of the arrays doesn’t have value then I don’t want to show that section.
4
Answers
Your numberOfSections will be the number of arrays. And the numberOfRowsInSection will be the count of each arrays for that section in your tableViewDataSource.
If there are no items in an array, then the rows will be zero for that section.
You can do something like this
If the arrays can change dynamically (after the view is loaded), you can implement number of sections like that:
Your data source should look like this –
sectionModels = [[cellModels]]
The outer array represents number of sections and inner array represents number of cells in that section.