我正在使用 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/