Collection-View-in-a-Table-View-Cell icon indicating copy to clipboard operation
Collection-View-in-a-Table-View-Cell copied to clipboard

Could not cast value of type 'UIViewController' to 'UICollectionViewDataSource'

Open HikmatDashdamir opened this issue 9 years ago • 6 comments

The error appears whenever i want to open a view which is inside container view

HikmatDashdamir avatar Sep 26 '16 16:09 HikmatDashdamir

Which line of code?

ashfurrow avatar Sep 26 '16 16:09 ashfurrow

func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) { guard let tableViewCell = cell as? TimeLineTableViewCustomCell else {return}

    let castSelf = self as! protocol <UICollectionViewDataSource, UICollectionViewDelegate>//THIS LINE

    tableViewCell.setTagsCollectionViewDataSourceDelegate(castSelf, forSection: indexPath.section)
    tableViewCell.tagsCollectionViewOffset = tagsStoredOffsets[indexPath.row] ?? 0
}

HikmatDashdamir avatar Sep 26 '16 16:09 HikmatDashdamir

What version of Xcode/Swift are you using? I haven't updated this tutorial for Swift 3 yet. I'll open an issue.

ashfurrow avatar Sep 26 '16 17:09 ashfurrow

I am using Swift 2 and xcode version is 7. Just for your information. This code works without any error for the different view. But it gives error now. I thinks there is problem in my viewcontroller maybe

HikmatDashdamir avatar Sep 26 '16 17:09 HikmatDashdamir

Same thing here. I'm trying to create this example by just code (not using the IB), And I'm getting stuck when trying to use de Delegate and DataSource function.

screen shot 2016-10-15 at 8 14 13 pm

This is the function inside the Custom Cell Class:

screen shot 2016-10-15 at 8 14 25 pm

I'm missing something?

Cheers!

gabovanlugo avatar Oct 16 '16 01:10 gabovanlugo

Sorry, I haven't had time to update this to Swift 3 yet. It looks like the ReviewViewController doesn't conform to the delegate/datasource protocols. Can you double-check that?

ashfurrow avatar Oct 16 '16 14:10 ashfurrow