无法使类型的视图出列:标识为

时间:2016-07-01 18:19:43

标签: xcode swift2 uicollectionview identifier

我正在创建一个集合视图。我以编程方式设置CollectionViewController并创建customCell文件。我在故事板中设计了单元格。我以前做过这个,它完美地运作了。但由于某种原因,我不断收到此错误。我的CustomCell类在故事板中连接。标识符与collectionviewcontroller方法中指定的标识符完全相同。我已经清理,退出并重新启动了xcode。我甚至试图用另一个我熟悉的单元接口来运行collectionviewcontroller。无论我做什么,我都会遇到这个标识符问题。这是一些代码

import Foundation

import UIKit

import Alamofire

class CommentsCollectionViewController: UICollectionViewController, UICollectionViewDelegateFlowLayout {
    override func viewDidLoad() {
        super.viewDidLoad()

        self.collectionView?.backgroundColor = UIColor(white: 0.85, alpha: 1)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 1
    }

    override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        let cellIdentifier = "CommentsCollectionViewCell"
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier(cellIdentifier, forIndexPath: indexPath) as! CommentsCollectionViewCell

        return cell
    }

}

这是我的CollectionViewCell:

import Foundation
import UIKit
import Cosmos

class CommentsCollectionViewCell: UICollectionViewCell {

    @IBOutlet weak var profileImageView: UIImageView!
    @IBOutlet weak var usernameLabel: UILabel!
    @IBOutlet weak var userRatingView: CosmosView!
    @IBOutlet weak var compatibilityLabel: UILabel!
    @IBOutlet weak var commentLabel: UILabel!

    override func awakeFromNib() {
        super.awakeFromNib()
    }
}

StoryboardIdentityInspector

StoryboardAttributesInspector

这是我的错误:

2016-07-01 10:55:40.349 ViewerReviewsApp [6377:289741] ***由于未捕获的异常终止应用程序' NSInternalInconsistencyException',原因:'无法将某种视图出列:带标识符CommentCell的UICollectionElementKindCell - 必须为标识符注册一个nib或类,或者在故事板中连接原型单元格'

***第一次抛出调用堆栈: (     0 CoreFoundation 0x000000010e05bd85 exceptionPreprocess + 165     1 libobjc.A.dylib 0x00000001104c7deb objc_exception_throw + 48     2 CoreFoundation 0x000000010e05bbea + [NSException raise:format:arguments:] + 106     3基金会0x000000010eb74d5a - [NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 198     4 UIKit 0x000000010f7d4a60 - [UICollectionView _dequeueReusableViewOfKind:withIdentifier:forIndexPath:viewCategory:] + 2009     5 UIKit 0x000000010f7d4ebc - [UICollectionView dequeueReusableCellWithReuseIdentifier:forIndexPath:] + 169     6 ViewerReviewsApp 0x000000010d729ee7 _TFC16ViewerReviewsApp25CommentFeedViewController14collectionViewfTCSo16UICollectionView22cellForItemAtIndexPathCSo11NSIndexPath_CSo20UICollectionViewCell + 151     7 ViewerReviewsApp 0x000000010d729f9f _TToFC16ViewerReviewsApp25CommentFeedViewController14collectionViewfTCSo16UICollectionView22cellForItemAtIndexPathCSo11NSIndexPath_CSo20UICollectionViewCell + 79     8 UIKit 0x000000010f7c308f - [UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:isFocused:] + 483     9 UIKit 0x000000010f7c6d96 - [UICollectionView _updateVisibleCellsNow:] + 4988     10 UIKit 0x000000010f7cb575 - [UICollectionView layoutSubviews] + 258     11 UIKit 0x000000010f006980 - [UIView(CALayerDelegate)layoutSublayersOfLayer:] + 703     12 QuartzCore 0x0000000115522c00 - [CALayer layoutSublayers] + 146     13 QuartzCore 0x000000011551708e _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366     14 QuartzCore 0x0000000115516f0c _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24     15 QuartzCore 0x000000011550b3c9 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277     16 QuartzCore 0x0000000115539086 _ZN2CA11Transaction6commitEv + 486     17 UIKit 0x000000010ef7819b _afterCACommitHandler + 174     18 CoreFoundation 0x000000010df80c37 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 23     19 CoreFoundation 0x000000010df80ba7 __CFRunLoopDoObservers + 391     20 CoreFoundation 0x000000010df767fb __CFRunLoopRun + 1147     21 CoreFoundation 0x000000010df760f8 CFRunLoopRunSpecific + 488     22 GraphicsServices 0x00000001153e5ad2 GSEventRunModal + 161     23 UIKit 0x000000010ef4bf09 UIApplicationMain + 171     24 ViewerReviewsApp 0x000000010d738ad2 main + 114     25 libdyld.dylib 0x0000000111d1392d start + 1 )

还有什么我可以做的才能使这项工作?

1 个答案:

答案 0 :(得分:1)

我想出了这个问题。这是我实例化视图控制器的方式。我必须这样呈现:

    let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
    let commentsView = storyBoard.instantiateViewControllerWithIdentifier("seeComments")

    self.presentViewController(commentsView, animated: true, completion: nil)

其中“seeComments”是故事板中的CollectionViewController。