我有一个用 Swift 编写的框架/模块,它提供了一些具有 IBDesignable 功能的自定义控件。
目前我正在开发一个基于 CollectionView 的控件。CollectionView 和自定义 CollectionViewCell 构建在 Nib 文件中。要加载 CollectionViewNib 并添加 Designable 功能,我使用这个NibDesignable类。初始化 CollectionView 后,我将 CollectionViewCell 注册如下:
let cellIdentifier = "collectionViewCell"
required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.setup()
}
override init(frame: CGRect) {
super.init(frame: frame)
self.setup()
}
private func setup() {
let bundle = NSBundle(forClass: self.dynamicType)
self.collectionView.registerNib(UINib(nibName: "CollectionViewCell", bundle: bundle), forCellWithReuseIdentifier: self.cellIdentifier)
}
将我的框架作为嵌入式二进制文件添加到另一个应用程序后,我可以按预期使用我的新自定义 CollectionView,但不幸的是,Designable 功能无法正常工作,而是收到以下错误消息:
IB Designables: Failed to update auto layout status:
The agent raised a "NSInternalInconsistencyException" exception:
view reuse identifier in nib (ibCollectionViewCell) does not match the identifier used to register the nib (collectionViewCell)
如上所述,我的控制在模拟器和手机上工作,所以不,我不使用不同的标识符。我不知道 XCode 从哪里得到这个 ibCollectionViewCell标识符,但是当我将它用作我的 CollectionViewCell 的标识符时,每件事都像一个魅力。
这个标识符来自哪里以及为什么 XCode 不能用我自己的标识符加载我的自定义 CollectionViewCell 的任何想法?