Swift   发布时间:2022-03-31  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Swift 关联Storyboard中的controller解决UICollectionView must be initialized with a non-nil layout parameter大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

在开发中会遇到已经写好的Storyboard中需要添加新的功能的时候,需要将Storyboard中的Controller实例化后才能进一步地操作,不然会出现类似'UICollectionView must be initialized with a non-nil layout parameter'这种类似的错误,原因是工程中的类要调用Storyboard中的Controller,但是Storyb
@H_696_10@

在开发中会遇到已经写好的Storyboard中需要添加新的功能的时候,需要将Storyboard中的Controller实例化后才能进一步地操作,不然会出现类似'UICollectionView must be initialized with a non-nil layout parameter'这种类似的错误,原因是工程中的类要调用Storyboard中的Controller,但是Storyboard中的Controller却没有找到对应的类。因此解决的办法如下:

1.创建Storyboard中Controller对应的类对象,并将Controller和类关联,然后设置id(我的CollectionViewController放在TabbarController中)

2.如果要调用则用如下代码

<span style="white-space:pre">	</span>var photoView = PictrueTabBarController()
        photoView = UIStoryboard(name: "Main",bundle: nil).instantiateViewControllerWithIdentifier("tabbar")
<span style="white-space:pre">	</span>as! PictrueTabBarController

大佬总结

以上是大佬教程为你收集整理的Swift 关联Storyboard中的controller解决UICollectionView must be initialized with a non-nil layout parameter全部内容,希望文章能够帮你解决Swift 关联Storyboard中的controller解决UICollectionView must be initialized with a non-nil layout parameter所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。