【发布时间】:2016-01-04 21:32:57
【问题描述】:
我正在尝试从一个视图控制器转移到另一个视图控制器,并将数据传递给下一个控制器,但我不断收到此错误:
无法将 ViewController 类型的值转换为 [VC2]
设置如下:
-
NavigationController是 VC1 的初始入口点 -
ViewController1是一个collectionViewController与 VC2 的显示 segue -
ViewController2是一个viewController,只有一个容器可以嵌入 VC3 -
ViewController3是带有静态表的tableViewController和 集合视图。
VC3 是我的destinationViewController 并嵌入在 VC2 中。当我从 VC1 中选择 collectionViewCell 时,我得到 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
}
}
因为UITableViewController 是UIViewController 的子类,所以这段代码应该可以正常工作。我做错了什么?
** 使用类型继承和确切错误消息更新问题: **
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] Interface Builder 文件中的未知类 _TtC17UITableViewHeader14ViewController。
无法将 'UITableViewHeader.ViewController02' (0x107a38360) 类型的值转换为 'UITableViewHeader.ViewController03' (0x107a38a50)。
【问题讨论】:
-
类 ContainerViewController: UIViewController
-
请包括不同控制器的类型继承,并包括确切的错误消息,不要改写,不要重新输入,复制和粘贴它。
-
请编辑实际问题,不要在评论中发帖。
-
在调试器中我输入:po secondVC.image 错误:执行被中断,原因:EXC_BAD_ACCESS (code=EXC_I386_GPFLT)。进程已经返回到表达式求值前的状态。
-
检查故事板中视图控制器的类
标签: ios iphone swift uiviewcontroller collectionview