gpt4 book ai didi

ios - 无法将类型 'UIViewController' 的值转换为 UITableViewController

转载 作者:行者123 更新时间:2023-11-30 14:01:03 25 4
gpt4 key购买 nike

我试图从一个 View Controller 切换到另一个 View Controller ,并将数据传递到下一个 Controller ,但我不断收到此错误:

Could not cast value of type ViewController to [VC2]

设置如下:

  • NavigationController 是 VC1 的初始入口点
  • ViewController1 是一个 collectionViewController,显示转场至 VC2
  • ViewController2 是一个 viewController,只有一个嵌入 VC3 的容器
  • ViewController3 是一个带有静态表格的 tableViewController Collection View 。

enter image description here

VC3 是我的 destinationViewController 并嵌入到 VC2 中。当我从 VC1 选择一个 collectionViewCell 时,我收到信号 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
}
}

由于 UITableViewControllerUIViewController 的子类,因此这段代码应该可以正常工作。我做错了什么?

** 更新了问题的类型继承和确切的错误消息: **

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).

最佳答案

更改代码中的这一行

let secondVC: ViewController02 = (segue.destinationViewController as? ViewController02)!

let secondVC:ViewController02 = segue.destinationViewController as! ViewController02

或者简单地:

    let secondVC = segue.destinationViewController as! ViewController02

关于ios - 无法将类型 'UIViewController' 的值转换为 UITableViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32995837/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com