Programmatically create instance of UICollectionViewCell from storyboard - ios

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!

Related

iOS - UITableViewCell in different Storyboard

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

How I can be reusable design custom cells for other view controllers?

I want to design a custom cell for the TableView but want to reuse the same cell for other view Controllers. Before .xib used files, my question is if they are the only option or you can do something like that with the Storyboard.
Yes, You can reuse custom cell for many tableviews creating "CustomCell" class.
To reuse custom cell you have to #import"yourcustomcell" in viewcontroller where ever you want.
Yes.
You can do it and can learn step by step from custom table view cell.

Swift - Outlets cannot be connected to repeating content

The full error is: The playerView outlet from the TableViewController to the AVPlayerView is invalid. Outlets cannot be connected to repeating content.
Similar answers like this one have not worked (assuming I am attempting them correctly, I'm very new to iOS).
All I want is a view within a TableViewCell.
I've tried dragging a View in Storyboard to the contentView (and cell) of my TableViewCell, assigning it a class of AVPlayerView: UIView (and a subclass of tableViewCell: AVPlayerView: UITableViewCell), then ctrl+dragging from that view in the storyboard into my TableViewController. Then it doesn't compile. Really confused, thanks for the help.
Your table view can have static content or dynamic content.
If you want the table view to have always the same content, set it to static (in interface builder), and then you can link the outlets like that, in the UIViewController.
If you want the table view cells to change dynamically, you cannot do it that way. Because you could repeat cells and the outlet would be ambiguous. You need to create a UITableViewCell subclass for your cells, and create the outlets there.
To clarify: in dynamic table mode, you need to ctrl+drag the outlet into the UITableViewCell subclass, not the view controller.
Very simple solution is:
Just take the view or NSLayoutConstraint reference outlets in the subclass of table view cell instead of table view controller and access using object of table view cell in cellForRowAtIndexPath method or any other method.

UICollectionView supplementary view in interface builder

For UICollectionViewCell, you can drag&drop a cell in interface builder. Then you can call dequeueReusableCellWithReuseIdentifier in your datasource and everything works just fine.
But how are you supposed to do this with accessory views? I tried drag&dropping a new UICollectionReusableView from the sidebar and I also tried enabling the footer option of the collection view.
In both cases I get the error "could not dequeue a view of kind". Sure you can register the class, but then you have to add all your subviews programmatically.
Or you can use a separate xib file and register that. However I like to keep everything within the collection view instead of having a separate xib file for every view.
You don't have to register the cells, then why should you have to explicitly register the supplementary cells.
What's the trick to do this in interface builder?

Using NIBs in UIStoryboard

For an ipad application in ioS5.0 using arc and storyboard, i wanted to create another custom view and instantiate several instances of that view within a scrollview so as to show a scrollable train of these custom views. To do this, I created the custom view in XIB file, however, how should I instantiate this view in the ViewController being refrenced within the storyboard. The custom view also has a gesture recogniser within it.
thank you in advance for your help on this.
I don't think there is a way to instantiate a nib backed view from a storyboard. You can do most of the layout in your storyboard, but then you will have to programmatically build your nib backed views and add them to the scroll view.
As a side note, it sounds like you are building something that could be solved with a UITableView and a prototype cell. Here is a pretty good tutorial.

Resources