【发布时间】:2017-10-03 13:43:11
【问题描述】:
我正在做一个简单的可可豆荚,它是一个自定义 UICollectionView。但我无法使用 UICollectionViewCell 的 xib 文件。我收到错误:由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“无法在包中加载 NIB:“NSBundle(已加载)”,名称为“CWNumberedCollectionViewCell”。
import UIKit
class CWNumberedCollectionViewCell: UICollectionViewCell {
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
}
import Foundation
import UIKit
public class CWCollectionViewNumbered: UICollectionView{
let cellIdentifier = "CWCell"
public init(frame: CGRect, layout: UICollectionViewFlowLayout, parent: UIView) {
super.init(frame: frame, collectionViewLayout: layout)
self.allowsMultipleSelection = true
self.delegate = self
self.dataSource = self
self.register( UINib.init( nibName:"CWNumberedCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: cellIdentifier)
self.backgroundColor = UIColor.blue
}
required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override public func selectItem(at indexPath: IndexPath?, animated: Bool, scrollPosition: UICollectionViewScrollPosition) {
print("tapped")
}
}
【问题讨论】:
标签: ios swift cocoapods bundle xib