如何以编程方式推送 UICollectionView? [复制]

Posted

技术标签:

【中文标题】如何以编程方式推送 UICollectionView? [复制]【英文标题】:How to push a UICollectionView programmatically? [duplicate] 【发布时间】:2016-06-21 11:53:00 【问题描述】:

当按下按钮时,我试图按下UICollectionViewController。我正在使用它来推送它:

RewardsCollectionViewController* rvc = [[RewardsCollectionViewController alloc] init];                 
[self.navigationController pushViewController:rvc animated:YES];

但是当我点击按钮时,应用程序崩溃并给我以下消息: UICollectionView must be initialized with a non-nil layout parameter在我的RewardsCollectionViewController 课堂上我什么都没做,我只是将numberOfItemsInSection 更改为1

我可能有一个可能的解决方案here,但我没有在该页面上找到我的答案。因为它在某种程度上与UICollectionViewFlowLayout 有关,我不知道那是什么。

【问题讨论】:

你用谷歌搜索了错误吗? 检查:***.com/questions/24288927/… 【参考方案1】:

storyboard 提供给您的COllectionViewController,然后像这样更改您的代码

 RewardsCollectionViewController* rvc = [self.storyboard instantiateViewControllerWithIdentifier:@"yourIdentifer"];                 
 [self.navigationController pushViewController:rvc animated:YES];

希望对你有帮助

【讨论】:

以上是关于如何以编程方式推送 UICollectionView? [复制]的主要内容,如果未能解决你的问题,请参考以下文章