【发布时间】:2016-09-12 17:51:49
【问题描述】:
我知道有很多问题可以回答这个问题,但我的情况略有不同。如果您使用情节提要,大多数答案都告诉我删除这行代码:
collectionView?.registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: cellId)
但我不能这样做,因为我同时使用故事板和非故事板。
我从一个程序化的推送视图控制器(故事板控制器-标签栏控制器)转换到这个集合视图控制器(非故事板视图),如下所示:
func showChatLogController(user: User) {
let chatLogController = ChatLogController(collectionViewLayout: UICollectionViewLayout())
chatLogController.user = user
chatLogController.hidesBottomBarWhenPushed = true
navigationController?.pushViewController(chatLogController, animated: true)
}
我的集合视图代码似乎是写的,我不知道问题是什么。如果您需要在此处查看集合视图代码,则为:
let cellId = "cellId"
override func viewDidLoad() {
super.viewDidLoad()
collectionView?.backgroundColor = UIColor.whiteColor()
collectionView?.registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: cellId)
setUpInputComponents()
let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(SignUpViewController.dismissKeyboard))
view.addGestureRecognizer(tap)
}
override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 5
}
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(cellId, forIndexPath: indexPath)
cell.backgroundColor = UIColor.blueColor()
return cell
}
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
return CGSize(width: view.frame.height, height: 80)
}
由于某种原因,它不显示单元格。我不知道为什么。任何帮助将不胜感激。
PS:我不知道这是否重要,但要进入集合视图控制器,我来自标签栏控制器。
【问题讨论】:
-
有没有人对我很奇怪的情况有什么建议
-
嗨,Rohan,您解决了这个问题吗?我们似乎发生了完全相同的事情。我还注意到,如果我开始滚动单元格应显示的位置,它们会突然出现。
标签: ios swift uicollectionviewcell collectionview