0

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!


}
}
fellowProgrammer
  • 327
  • 3
  • 17
  • Do you have the class in a framework? – midori Oct 09 '16 at 17:00
  • No I don't think so, the class is a view controller and the subclass is in the view controller. – fellowProgrammer Oct 09 '16 at 17:46
  • It sounds very strange to me to put your subclass in `UIViewController` can you please provide a code sample? – midori Oct 10 '16 at 06:30
  • added code @midori – fellowProgrammer Oct 10 '16 at 12:42
  • 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` (http://stackoverflow.com/questions/24110811/uicollectionviews-cell-registerclass-in-swift). If this does not work please go through any tutorial on the web which deals with custom cells in collectionviews. – midori Oct 10 '16 at 12:58

1 Answers1

2

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.

fellowProgrammer
  • 327
  • 3
  • 17