Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reloading TableView from CollectionViewCell

Does anyone have idea how to reload TableView that's inside of CollectionViewCustomCell? I have an IBOutlet of that Table and the only way to access that Table is inside cellForItemAtIndexPath method where I can access my CollectionViewCustomCell and through that access the Table.

cell.tableViewInsideOfCollectionViewCell.reloadData()

But this only works on the first load, when I change CollectionView source it will not reload TableView.

If you need anymore info, please ask!

Thanks in advance!

like image 603
Srdjan Avatar asked Apr 25 '26 11:04

Srdjan


1 Answers

You can get the cell using collectionView.cellForItem(at: IndexPath) method. Then cast it to the type of cell that contains the tableView. Now you have access to that cells properties and can reload the tableView.

guard let cell = collectionView.cellForItem(at: IndexPath(row: , section: )) as? CustomCellWithTableView else { return }
cell.tableView.reloadData()
like image 92
JustinM Avatar answered Apr 28 '26 01:04

JustinM



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!