0
votes

I am working with Xcode 7 and swift.

I am trying to connect a label that is on a Collection View prototype cell to my code. I know to do this, I have to make a subclass of UICollectionViewCell and put it in that class instead of the view controller, which I did. I run the app immediately after adding the outlet to the subclass, and the app crashes. I noticed at the top of the error message it says: Unknown Class nameOfSubclass in Interface Builder File. I have looked at other stack overflow questions and they say it is a simple matter of setting the module under the custom class. I did this, but the app still crashes and now it says: Unknown class _TtC13 (app name / module name) 17(nameOfSubclass) in Interface Builder file.

identity inspector of the prototype cell

identity inspector of the UICollectionView

Code

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!


}
}
1
Do you have the class in a framework? - midori
No I don't think so, the class is a view controller and the subclass is in the view controller. - fellowProgrammer
It sounds very strange to me to put your subclass in UIViewController can you please provide a code sample? - midori
added code @midori - fellowProgrammer
Ok. Please use Upper Case letters for class names e.g. hourlyWeatherCell as HourlyWeatherCell . I am only able to guess - this issue may have many of other causes. What I am missing is that you should register your custom classes against the UICollectionView (stackoverflow.com/questions/24110811/…). If this does not work please go through any tutorial on the web which deals with custom cells in collectionviews. - midori

1 Answers

2
votes

With a little tinkering I got it to work. For some reason Xcode was not compiling the subclass it the UIViewContoller. I simply moved the subclass out of the view controller class (making the subclass a class), and everything worked fine.