Adding a container view to UICollectionViewCell - ios

I am trying to add a container view to a UICollectionViewCell in interface builder but Xcode issues an error error: Illegal Configuration: Container Views cannot be placed in elements that are repeated at runtime. Will making the UICollectionViewCell static would solve this? If so, how would you make the UICollectionViewCell static?

What I guess you are trying to do, is placing a UIViewController into a dynamically generated UITableViewCell.
If so, this isn't possible if the cell you are generating are dynamic. If you know a priori that the cells will always be in a fixed number, you can generate them by Interface builder setting the cells to static.
If instead you only want to add a container view to your cell in order to put other objects in it, you need to add a UIView object, not a UIViewController.

Related

UICollectionViewCell subclass that uses its parent's xib

I have a custom UICollectionViewCell subclass, lets call it CellClassOne, and I'm trying to create a subclass of that cell, called CellClassTwo so I can change a property and modify some constraints in its view in awakeFromNib.
However, when I register my cell in my collectionView it gets loaded form the xib, so it has the parent's class, CellClassOne. How can I create CellClassTwo that can be dequeued by my collectionView and have its class set to CellClassTwo (and any properties and ovverides with that)?
I'm trying to avoid setting my properties in cellForRow since I'm trying to reuse my cell in different parts of my app but need slightly different paddings for some views, and I don't want to create duplicate Xib files for this.
If I must go with the duplicate files, then it may be better to stick with configuring the views in cellForRow.
Iā€™m not sure that you can achieve what you are looking for via xib, but a viable way that should work is creating the CellClassOne programmatically ( including all the subviews and related layout constraints) following the cell lifecycles, and then subclassing it with CellClassTwo accordingly. That way you should be able to register the cell like ā€˜ collectionView.register(CellClassTwo.self, forCellReuseIdentifier: "myCell")ā€˜.

Can I create custom cells like these in swift 5 ios using messageKIt?

I am building a chat app and I am new to ios, I want to build custom cells like these using messageKIT, can anybody help me with any resource or code?
Yes, what you want is definitely possible!
You may refer to this GitHub repo that contains a text document/guide on how to configure customs cells with MessageKit and examples.
An extract from the repo:
Note: If you choose to use the .custom kind you are responsible for all of the cell's layout. You can design the cell in code or Interface Builder. Any UICollectionViewCell can be returned for custom cells which means any of the styling you provide from the MessageDisplayDelegate will not affect your custom cell, even if you subclass your cell from MessageContentCell.
Creating a custom cell involves four parts:
Build a cell in Interface Builder or code that inherits from UICollectionViewCell
Set the size of your cell. Subclass MessageSizeCalculator if you want your cell to have the default MessageKit layout design. Subclass CellSizeCalculator if you want to further customize your own cell design. The implementation of this class will allow your custom cell to automatically size itself within the messagesCollectionView.
Add your custom cell size to the collection view flow layout. Subclass MessagesCollectionViewFlowLayout, and use the custom message size calculator from step 2, above.
Register your custom cell and reference your custom collection view flow layout.

UICollectionViewCell Overlay View

I have a UICollectionViewCell with .xib.
Here is the Structure of the xib file
As you can see every element at the same level and 3 image views and a single button. But at run time there is a UIView in front these elements.
UI structure at runtime.
I need to understand why this is happening and what is the solution. Because of this overlay UIView clicks events not pass down to the button.
Problem was I was using UIView in the XIB that created by default when creating a xib file. Instead of using that I tried with UICollectionViewCell element as the parent and it worked for me.

How to access UITableViewCell from UITableView in different UIViewController?

I have very complex cell in UITableView within UIViewControllerA. Now I need to use the same cell within UITableView of UIViewControllerB.
How to do this without copy and paste views from one scene to another?
Do not wanna use xib approach.
Is it related to registerNib:forCellReuseIdentifier?
You mentioned you don't want to use xib. Storyboards don't support this and therefore the last option you have is to construct your UITableViewCell in code. With the new Auto Layout anchors, it's not that bad.

Custom UITableViewCell using storyboard with some cells

I have a TableView in which a most cells are pretty standard. I make them buy using static cells in Storyboard. However, one cell I would like to customize probably using an XIB file so I would need to load it programmatically.
In the TableView's data source, is it possible to handle loading XIB view for this particular cell only, while leaving other cells to what's delineated in the static cells in the Storyboard? Or is it an all or nothing thing where I need to just give up using static cells altogether?
The rationality for doing this is that I would like to make Storyboard to look as close to the real thing as possible. Right now if I provide a data source, the static cells in the storyboard would have no effect on the actual output and is not in any sense linked to the actual output.
Yes, it is possible. Set the custom class for the custom cell. If you wish to customise it from code, just connect it as an IBOutlet to the UITableViewController.

Resources