ios - UICollectionElementKindCell 的 registerNib 在使用 presentViewController 动画时不起作用 : false

标签 ios objective-c swift uicollectionviewcell presentviewcontroller

我在 viewWillAppear() 中注册了 registerNib 方法,当我使用 presentViewController(viewController, animated: true, completion: nil) 时,它工作正常。

但是当我使用 presentViewController(viewController, animated: false, completion: nil) 时,它不起作用。

错误 消息如下。我必须在 Storyboard上注册吗?无法通过程序注册?

'NSInternalInconsistencyException', 
reason: 'could not dequeue a view of    
kind: UICollectionElementKindCell with identifier NoContentsCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'

最佳答案

在您的 Storyboard中设置可重复使用的标识符。

enter image description here

并使用collectionView.dequeueReusableCellWithReuseIdentifier

对于注册类

self.collectionView.registerClass(MenuCell.self, forCellWithReuseIdentifier:"menuCell")

注册 Nib

var nib=UINib(nibName: "MenuCell", bundle:nil)
collectionView.registerNib(nib, forCellWithReuseIdentifier: "menuCell")

你能从中得到帮助吗

关于ios - UICollectionElementKindCell 的 registerNib 在使用 presentViewController 动画时不起作用 : false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31308666/

相关文章:

ios - Collection View 的自定义布局不会更新

ios - 在 IOS 的 ImageView 中显示多个图像

ios - 永远不会调用 TableView cellForRowAtIndexPath(iOS、Swift)

swift - macOS 命令行代码在 Swift 中获取数据的现代方式,并带有进度通知

ios - Swift 自定义 uitableViewCell

ios - swift:如何将base64String编码的图片保存到本地目录

ios - 防止同时按下按钮

android - 列出 Android 目标时出错

ios - AVAudioPlayer 是不是重启了背景音乐?

python - NSPipe - 如何将返回的数据转换为 NSArray