ios - How to display a UItableView in UicollectionViewCell? -
so have collection view 3 cells, each of has tableview in it. obviously, each collection view cell has load it's table view different data table view cells.
my first thought make collection view delegate , datasrouce of table view, so, datasource need know collection view cell being loaded.
also thought of making separate class ds , delegate both collection view , table view, again, i'm stuck on how tableview ds know collection view cell it's being loaded from.
any thoughts?
edit:
after make assignment, datasource field nil. missing here?
func collectionview(_ collectionview: uicollectionview, cellforitemat indexpath: indexpath) -> uicollectionviewcell { guard let cell = collectionview.dequeuereusablecell(withreuseidentifier: reuseidentifier, for: indexpath) else { return uicollectionviewcell.init() } cell.backgroundcolor = uicolor.clear cell.thetableview.datasource = requestedtabledatasource.init() cell.thetableview.delegate = self cell.thetableview.reloaddata() return cell } class requestedtabledatasource: nsobject, uitableviewdatasource { func tableview(_ tableview: uitableview, numberofrowsinsection section: int) -> int { return 16 } func tableview(_ tableview: uitableview, cellforrowat indexpath: indexpath) -> uitableviewcell { guard let cell = tableview.dequeuereusablecell(withidentifier: "requestedcell") as? intervieologistrequestedcell else { return uitableviewcell.init() } cell.setupcellfor(name: "dan", image: uiimage.init(named: "dan")!) return cell }
}
if this:
let foo = requestedtabledatasource.init() cell.mytableview.datasource = foo
then datasource field set, numberofrows gets called, cellforrowatindexpath doesn't.
you can set tableview.tag unique integer , identify later in delegate methods using that, recommend keeping seperate datasource/delegate each tableview, cleaner.
don't make collectionview or other view object datasource/delegate.
eg set
collectionviewcell.tableview.tag = index; collectionviewcell.tableview.delegate = commondelegate;
or
collectionviewcell.tableview.delegate = uniquedelegate; // better choice
Comments
Post a Comment