Use the same cell type in different screens in storyboard without duplication - ios

I have a UITableViewController using many different types of cells.
In the code, each of those cells has its own UITableViewCell subclass.
In storyboard, they are all in the same screen.
Now I need to use the same cells in other screens as well.
How do I do that without having to copy and paste my cell in storyboard in the new screens?
I don't want any duplication in storyboard when it comes to layout and constraints.

Your best option is probably to move the cells into separate XIB files. You need to use the registerNib: method on UITableView to tell the table where it can find the cell definition.

You can create a
UITableViewCell
class.
Use this class as the cell's custom class and Ctrl link your cell's items to the property in this class.
Then you can use this cell class for other table views

Related

Customs UIView's in TableViewController

I've some difficulties to understand how this UIViewController is made. I think a scheme of the UIView's used in this UIViewController will help me to understand
Here is the screenshot of the UIViewController
I want to make something like that : put an UIView with UILabel, UIImageView, UITextField,... inside a TableView, between two cells.
You can't put normal views between cells. You can use various types of custom cells to get the look you want, but a table view manages its view hierarchy and you absolutely cannot add your own views to it.
You can use UITableViewController with static cells for this layout scheme and perform this layout directly from storyboard.
Alternatively you can put custom views inside vertical stack view and put it all into scrollview.
You can create your own customised tableHeaderFooterView and cells. Then you will only need to register them to the tableView and do logic on the cellForRowAt and headerFooterViewInSection methods.

iOS alternative for Androids <include> tag?

How am I supposed to reuse views in iOS?
For example, I have a view that returns as a CollectionViewCell, inside of a UITableViewCell and on a specific spot in a UIViewController.
What is the recommended way to deal with this?
Do I make a xib and add a holder view everywhere I need it?
But, then to react to size changes, I need to add constraints in code, which seems to be too much hassle just for a simple inclusion of a xib.
Is there a feature in Xcode I can use?
Create an UICollectionViewCell in a XIB. Then this cell is placed inside an UICollectionView. You can place this UICollectionView basically everywhere, also inside an UITableViewCell. As the UICollectionView can be auto-layout constraint in the Storyboard the size changes automatically. No need for programmatic constraints. When you want to reuse the UICollectionViewCell just put it inside another UICollectionView in another UIViewController or UITableViewCell.
Btw: to use this just as "reusing"-feature you can disable the scrolling in the UICollectionView.

Subclassing UITableViewCell only works for some StaticTableView cells?

I have a Static Tableview with multiple cells. I have created a file subclassing UITableview cell which I then go on storyboards and add is a the class for the cells.
The issue is only one of the many cells work when I go on storyboard and add it as a class?
Why is this happening?

Why there is no prototypeCell in View.xib?

When we add any UITableView to UIViewController through storyboard we will see screen like this
and there is an option for PrototypeCell top right side. But when we add the UITableView to View.xib we will see screen like this
and here there is no PrototypeCell. I am not understanding this why there is difference. Please explain.
It's different because when you drag and drop a UItbaleViewController in the UIStoryboard, it assume that you will use dynamic cells, and when you drag and dropped a simple UITableView it changed the property to static, which means that you will provide different UI and informations to each cells.
You can change the style to dynamic instead of plain if you want to have prototype cells.
PrototypeCell not available in xib file, storyboard only.
You can use separated xib for UITableViewCell in this case. (in storyboard case you also can use separated xib for cells)

How to edit cells on UITableView using XIB, just like Storyboard

I'm running on some glitch or may be functionality lack.
I cannot edit UITableView when using XIB, just like Storyboard does.
There is something i'm missing??
Apple does not allow being able to edit cells directly in an XIB. You have to create a separate XIB for the cell and in the table view data source return a cell with that cell subclass
Maximillian is right — so instead of designing your cells in a XIB, I would design it in a storyboard, which then you could link into a larger storyboard with RBStoryboard.

Resources