[英]How to make a reusable view cells for UITableViewCell and UICollectionViewCell ? I've tried to sublassing UIView for the cell but it's not working
I want to reuse my UITableViewCell to my UICollectionViewCell. 我想将UITableViewCell重用到UICollectionViewCell。
Until now, I always use 2 xibs, 1 for UITableViewCell
and 1 for UICollectionViewCell
and I think it's kinda waste. 到目前为止,我始终使用2个xib,其中1个用于UITableViewCell
而1个用于UICollectionViewCell
,我认为这有点浪费。
I've tried to subclassing UIView
for the cell but it's not working. 我尝试将UIView
子类UIView
该单元,但是它不起作用。
A way to do this is by using reusable views. 一种方法是使用可重用的视图。 Here is a Github project that can help: NibDesignable 这是一个可以帮助您的Github项目: NibDesignable
You can also do this without using the project I mentioned, but it does make it easier. 您也可以在不使用我提到的项目的情况下执行此操作,但这确实使它变得更容易。 You then create a UIView with a View nib and put all your UI into this as well as any code for setting the UI components. 然后,使用View笔尖创建一个UIView,并将所有UI以及用于设置UI组件的任何代码放入其中。 Then you create your UITableViewCell and UICollectionViewCell and then just use the view that you created. 然后,创建UITableViewCell和UICollectionViewCell,然后仅使用创建的视图。 You can also use prototype cells in a Storyboard for CollectionView or TableView if you prefer. 如果愿意,还可以在Storyboard中为CollectionView或TableView使用原型单元。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.