Reputation: 7638
I have the following design:
A table with multiple sections and multiple rows for each section. For each row I have a collection view.
I'm having a problem to assign delegates to the collections because of the multiple table sections.
How can I use the collection.tag to refer to a specific section and row of the table view?
Upvotes: 2
Views: 438
Reputation: 3708
Better Approach is to user Section Models
struct CellModel {
var collectionModel: [ModelType] = []
}
struct SectionModel {
headerModel: Any
cellModels: [CellModel] = []
}
var sections: [SectionModel] = []
// intialize array some where or API Response
in UITabelView delegate method
number of rows
return self.sections[section].cellmodels.count
number of sections will be
return self.sections.count
in cell for row at index
cell.cellModels = self.sections[indexpath.section].cellModels[indexpath.row]
In CellCustomClass
declare var cellModels: [ModelType] = []
Now TableCell consist collection view You can use this array as it data source
Upvotes: 0
Reputation: 423
A better approach would be
And connect the table view's delegate to view controller and connect the collection view's delegate to the table view cell.
Upvotes: 1