I want to use a UITableViewController which has four different type complex cell. Different team members are required to work on different custom UITableViewCell simultaneously. We are working on Git so to avoid conflicts I have been asked to make four different Storyboards for four different cell. But I cannot place a cell or simple UIView in different Storyboard without view controller. Please guide me, how do i implement it.
Please keep in mind that cells will be instantiated and added on
runtime
Create xib of your each cell, and register it in your UITableView , you can use this xib anywhere in your project and with the same CellIdentifier.
How to Make UITableVIewCEll XIB
Related
I originally had several UITableViewCells on a UIViewController with a UITableView. Then, I moved the UITableViewCells to a new UITableViewController I created because I wanted to make them static cells and the only way to make them static was to use them on a UITableViewController. However, after I moved, them, although everything was connected and all the cells were set to the right xib files, the app crashed and it said the outlets on the UITableViewCells, like my UILabels, were found nil. I then tried to create brand new UITableViewCells with brand new xib files on the UITableViewController, but then I couldn't even connect any outlets for any UILabels or anything else. Does anyone know how to troubleshoot this? All my code looks normal and I've been using UITableViews for a long time, just never creating static cells before.
I figured it out! In a UITableViewController with Static Cells you don't need to create a custom class for the cells and drag your outlets there (what I did); you can just drag your outlets directly onto the UITableViewController and it will work there.
I wonder if there is any way to replace all xib with storyboard. I am using a tableview which uses a custom cell. Usually all online resources and tutorials guide to make a xib and then load from delegate on a custom cell class. I dont want to use any xib in my project. How can I transfer those cell xib to storyboard and instantiate from there.
After some research and study I found that there is no such functionality in xib which cannot be replaced with storyboard. Thanks to #DonMag for comments and clue.
The only issue I was facing is to design uitableview cell, but prototype cell design can be used easily from storyboard. Here are some example how to use it.
I watched multiple videos on youtube and bought two books with explanations (O'Reilly).
It seems like a nib file is always used in one view controller.
The file-owner is usually the view controller which will implement that nib.
I couldn't find an example in which a nib file is used in multiple view controllers.
I did come across a couple of posts that found ways around this but the posts are old and many people leave warnings.
My initial urge to use a nib file was because I had a table view cell that was used in multiple tableViewControllers. The tableViewCell was prototyped in one of the TableViewControllers in storyboard.
I thought that creating a nib would decouple that cell from one specific TableViewController.
I can't say that I really understand the purpose of a nib file.
It seems like it's very similar to storyboard.
I ended up creating the tableViewCell in code and reusing it throughout my project.
So my question is what are nib files used for ?
Are they used to decouple a view from a specific view controller ?
Are they used to avoid duplication within one ViewController ?
Any insight would be helpful.
Yes, you can reuse xibs in many places within your app.
Xibs predate storyboards and act as factories for creating instances of UIView classes configured in Interface Builder. Using them to define the layout and attributes of a UIViewController's view and its subviews is one common use case but certainly not the only one.
A common place where a xib might be reused is when it contains a table or collection view cell. You could then register that xib with multiple table or collection views using register(_ nib: UINib?,
forCellWithReuseIdentifier identifier: String) to load instances of the cell when needed.
I have designed a collection view + custom cell as part of a view controller in Interface Builder. I would like to create an instance of that custom cell programmatically, just so I can use it for measuring it's dynamic size. How do I create an instance of an object from a storyboard based on it's name or it's reuse identifier (not by dequeueing a reusable cell). It it was a different xib, it would have been easier, but since it's all part of one storyboard I'm not sure how to accomplish that. Thank you!
This appears to be a storyboard editor issue because it's easy to do in code.
I have a UITableView with two different prototype cells. They have reuse identifiers, different accessories. I want selecting one type to trigger a segue to another view controller, and selecting the other to go to a different view controller. But as soon as I create the second segue in the storyboard editor, the first one is replaced. Even if I have named it.
It seems this should be a common enough scenario, I should be able to have multiple segues, and differentiate them in prepareForSegue.
I need to note, this is easy to do in the didSelectRowAtIndexPath for the view controller's table view delegate, but there I have to explicitly load the template from the storyboard (unless I use a generic and don't need a nib).
Has anyone been able to get this to work in the storyboard editor?
The only way I could think of to do this with how things currently work is by using two different types of prototype cells. (two separate classes) and assigning each different segue to each different subclassed prototype cell.