ios - Interface Builder 文件中的未知类 X

标签 ios swift uicollectionview xcode7 uicollectionviewcell

我正在使用 Xcode 7 和 swift。

我正在尝试将 Collection View 原型(prototype)单元格上的标签连接到我的代码。我知道要做到这一点,我必须创建 UICollectionViewCell 的子类并将其放入该类而不是我所做的 View Controller 。我在将 socket 添加到子类后立即运行该应用程序,但该应用程序崩溃了。我注意到错误消息的顶部显示:Interface Builder 文件中的未知类 nameOfSubclass。我看过其他堆栈溢出问题,他们说在自定义类下设置模块是一件简单的事情。我这样做了,但应用程序仍然崩溃,现在它说:Interface Builder 文件中的未知类 _TtC13(应用程序名称/模块名称)17(nameOfSubclass)。

identity inspector of the prototype cell

identity inspector of the UICollectionView

代码

import UIKit




class SecondViewController: UIViewController, UICollectionViewDelegate,  UICollectionViewDataSource  {


@IBOutlet weak var collectionView: UICollectionView!


private let reuseIdentifier = "hourlyWeatherCell"

func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
    // #warning Incomplete implementation, return the number of sections
    return 1
}


func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    // #warning Incomplete implementation, return the number of items
    return 48
}

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
    let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) //as! hourlyWeatherCell






    // Configure the cell



    return cell
}







override func viewDidLoad() {
    super.viewDidLoad()
    printDate()

    // Do any additional setup after loading the view.

    self.collectionView.dataSource = self
    self.collectionView.delegate = self


}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}














class hourlyWeatherCell: UICollectionViewCell {

    @IBOutlet weak var temperatureHLabel: UILabel!


}
}

最佳答案

稍加修改,我就让它工作了。出于某种原因,Xcode 没有编译 UIViewContoller 的子类。我只是将子类移出 View Controller 类(使子类成为一个类),一切正常。

关于ios - Interface Builder 文件中的未知类 X,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39944710/

相关文章:

ios - 如何从单元格中的按钮调用外部函数

swift - Collection View 单元格中的动态按钮宽度

ios - 如何通过在 swift playground 中传递 Int 数组来创建求和函数并调用它?

ios - 停止 UIKeyCommand 重复 Action

ios - Swift - 从 switch 语句中的字符串初始化枚举

swift - 如何使用 for 循环实例化字典(swift)

ios - UICollectionView 数据源方法未被调用,但正在初始化中设置

ios - 保存到核心数据崩溃

iphone - CustomTableCellView的实现-layoutSubviews需要调用super,NSInternalInconsistencyException

ios - 长按识别器结束后调用 wkwebview decidePolicyForNavigationAction