简体   繁体   English

在不同情况下使用一个UICollectionViewCell原型

[英]Use one UICollectionViewCell prototype for different situations

I try to create chat view with message bubbles using UICollectionView. 我尝试使用UICollectionView创建带有消息气泡的聊天视图。 I want to show message with attachments in one bubble, not in differnt bubbles. 我想在一个气泡中显示带有附件的消息,而不是在不同气泡中显示。 Maximum count of attachment is 10. 附件的最大数量为10。

|----------------------------| 
|       |------------|       |
|       |  Text      |       |
|       |------------|       |
|                            |
|       |------------|       |
|       |attacment 1 |       |
|       |------------|       |
|                            |
|       |------------|       |
|       |attacment 2 |       |
|       |------------|       |
|                            |
|       |------------|       |
|       |attacment 3 |       |
|       |------------|       |
|                            /  
|--------------------------\ \
                            \__>

My problem is: I don't want to create 10 prototype cells for each situation ( text + 1 attachment, text + 2 attachment, ..., text + 10 attachment). 我的问题是:我不想为每种情况创建10个原型单元(文本+ 1个附件,文本+ 2个附件,...,文本+ 10个附件)。

My question is: Can I create one subclass and prototype of UICollectionViewCell with all ui elements and constraints, then remove unneccesary ones in the code and use different reuseIdentifiers for each situation? 我的问题是:我可以创建一个具有所有ui元素和约束的UICollectionViewCell的子类和原型,然后在代码中删除不必要的元素并为每种情况使用不同的复用标识符吗? ( text + 1 attachment, text + 2 attachment, ..., text + 10 attachment). (文本+ 1个附件,文本+ 2个附件,...,文本+ 10个附件)。 Or may be I can solve my problem another way? 还是可以用另一种方式解决我的问题?

Another way would be the best. 另一种方法是最好的。 For instance, you could put a dynamic table view inside the collection view cell which enables you to add as many attachments as you want. 例如,您可以在集合视图单元格中放置一个动态表格视图,使您可以根据需要添加任意数量的附件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM