I'm trying to segue from one view controller to another, and pass data to the next controller, but I keep getting this error:
Could not cast value of type ViewController to [VC2]
Setup looks like this:
NavigationController
is initial entry point to VC1ViewController1
is acollectionViewController
with show segue to VC2ViewController2
is aviewController
with only a container to embed VC3ViewController3
is atableViewController
with static table and collectionView.
VC3 is my destinationViewController
and embedded in VC2. When I select a collectionViewCell
from VC1 I get Signal SIGABRT.
override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
selectedImage = UIImage(named: wholeArray[indexPath.row]["image"] as! String)!
selectedLabel = wholeArray[indexPath.row]["name"] as? String
self.performSegueWithIdentifier("show", sender: nil)
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
if (segue.identifier == "show") {
let secondVC: ViewController02 = (segue.destinationViewController as? ViewController02)!
secondVC.image = selectedImage
secondVC.label = selectedLabel
}
}
Since UITableViewController
is a subclass of UIViewController
, this code should work just fine. What am I doing wrong?
** Updated question with type inheritance and exact error message: **
class ViewController01: UICollectionViewController, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout {
class ViewController02: UIViewController {
class ViewController03: UITableViewController, UICollectionViewDataSource, UICollectionViewDelegate,UIScrollViewDelegate {
class HeaderView: UIView {
2015-10-07 11:26:27.384 UITableViewHeader[45474:3576139] Unknown class _TtC17UITableViewHeader14ViewController in Interface Builder file.
Could not cast value of type 'UITableViewHeader.ViewController02' (0x107a38360) to 'UITableViewHeader.ViewController03' (0x107a38a50).