这是错误:
Base.lproj/Main.storyboard: error: IB Designables: Failed to update auto layout status: The agent raised a "NSInternalInconsistencyException" exception: could not dequeue a view of kind: UICollectionElementKindCell with identifier WalletCurrencyCollectionCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard
中有钱包控件
电子钱包控件在UICOllectionView中有4个单元格,但它在故事板中给出了这个错误(但是当我启动代码时,一切正常,它只是在故事板中给出了错误)。但是,如果我设置的单元格数= 0,它工作正常,所以问题出在集合视图单元格
这是单元格的结构
这是钱包控制的结构
以下是钱包控制的代码:
import UIKit
class WalletCurrencyCollectionCell: UICollectionViewCell {
@IBOutlet var labelAccount: UILabel!
}
@IBDesignable class WalletControl: UIView, UIPickerViewDelegate, UIPickerViewDataSource, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
@IBOutlet var labelInYourAccount: UILabel!
@IBOutlet var labelOtherAccounts: UILabel!
@IBOutlet var collectionViewMain: UICollectionView!
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)!
setup()
}
override init(frame: CGRect) {
super.init(frame: frame)
setup()
}
func setup() {
view = loadViewFromNib()
view.frame = bounds
view.autoresizingMask = [.FlexibleHeight ,.FlexibleWidth]
addSubview(view)
// localizations
labelInYourAccount.text = "wallet_label_inYourAccount".localized
}
override func awakeFromNib() {
// register nib
let collectionCellNib = UINib(nibName: "WalletCurrencyCollectionCell", bundle: nil)
collectionViewMain.registerNib(collectionCellNib, forCellWithReuseIdentifier: "WalletCurrencyCollectionCell")
}
func loadViewFromNib() -> UIView {
let bundle = NSBundle(forClass: self.dynamicType)
let nib = UINib(nibName: "WalletControl", bundle: bundle)
view = nib.instantiateWithOwner(self, options: nil)[0] as! UIView
return view
}
override func intrinsicContentSize() -> CGSize {
// return CGSizeMake(200, labelSuper.maxY + 10)
let sizeOfView = viewContainerToMesherSize.systemLayoutSizeFittingSize(UILayoutFittingCompressedSize)
return sizeOfView
}
// MARK: - Collection view
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
// test
return 4
}
func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("WalletCurrencyCollectionCell", forIndexPath: indexPath) as! WalletCurrencyCollectionCell
// fill with information
return cell
}
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
collectionView.deselectItemAtIndexPath(indexPath, animated: true)
}
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
let width = collectionView.widthMy
return CGSizeMake(width, 100)
}
}
所以我不明白为什么我在关于笔尖的故事板中有这个错误,因为我注册了笔尖。应用程序启动后一切正常。我可以用这个故事板错误做什么(问题出在UICollectionView中,因为如果我设置了cell = 0,一切正常)?
答案 0 :(得分:0)
我通过使用服务器响应计算单元格数来解决这个问题(如果没有服务器响应钱包帐户,我返回0),所以在这种情况下,故事板总是认为我有0个单元格而且我没有任何警告,当我启动应用程序时,一切都还可以,因为我只是在UICollectionView中正确显示单元格
func help_getArrayOfUserCurrencyAccounts() -> [SCurrencyAccount] {
if let currentUser = ApiManager.sharedInstance.userService_currentUser {
return currentUser.arrayCurrencyAccounts
}
else {
return [SCurrencyAccount]()
}
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
let realAccountsCount = help_getArrayOfUserCurrencyAccounts().count
if realAccountsCount > 0 {
if realAccountsCount == 1 {
return realAccountsCount
}
else {
return realAccountsCount + 1 // so we can scroll through accounts
}
}
else {
return 0
}
}