I’m new at developing with XCode and Objective-C and I hope you can help me.
The problem is, I have an UITableViewController with an UITableView (created with the InterfaceBuilder).
The cells under the section headers are expandable.
Now I want to dynamically create multiple UITableViews under the existing TableView.
The style will be the same like the existing TableView’s style.
Could you tell me how it is possible to create these TableViews programmatically?
Thank you very much
Michael
From what you are saying try using a grouped table view. Check out this link for a quick overview, and go to the grouped table view section.
Edit found this example here:
Seems like it is what you are looking for. And a very cool idea also.
You’ll have to just make your own custom header row and just put that as the first row of each section. Subclassing the UITableView or the headers that are on there now would probably be a huge pain and I’m not sure you can easily get actions out of them the way they work now. You could easily set up a cell to LOOK like a header, and setup the
tableView:didSelectRowAtIndexPathto expand or collapse the section it is within manually.If I were you I’d store an array of booleans corresponding the the “expended” value of each of your sections. You could then have the
tableView:didSelectRowAtIndexPathon each of your custom header rows toggle this value and then reload that specific section.You’d then setup your number
numberOfRowsInSectionto check themybooleansvalue and return either 1 if the section isn’t expanded, or 1+ the number of items in the section if it is expanded.You would also have to update your
cellForRowAtIndexPathto return a custom header cell for the first row in any section.