簡體   English   中英

接口生成器文件中的未知X類

[英]Unknown Class X in Interface Builder File

我正在使用Xcode 7和Swift。

我試圖將Collection View原型單元上的標簽連接到我的代碼。 我知道要這樣做,我必須創建UICollectionViewCell的子類並將其放在該類中,而不是我所做的視圖控制器中。 將出口添加到子類后,我立即運行該應用程序,該應用程序崩潰。 我在錯誤消息的頂部注意到它:接口生成器文件中的未知類nameOfSubclass。 我看過其他堆棧溢出問題,他們說在自定義類下設置模塊很簡單。 我這樣做了,但是應用程序仍然崩潰,現在它說:Interface Builder文件中的未知類_TtC13(應用程序名稱/模塊名稱)17(nameOfSubclass)。

原型單元的身份檢查器

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。 我只是將子類移出了視圖控制器類(使子類成為一個類),並且一切正常。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM