UICollectionView supplementary view in interface builder - ios

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?

Related

UITableView - how to register a cell from secondary view?

If you drag a UITableViewCell onto the top toolbar of a view controller, it appears above the view controller in IB as a secondary view. This is nice because you can do all the layout there. But how do you then get a table view to load the cell from there?
This doesn't work:
[self.tableView registerClass:[MyCustomTableViewCell class] forCellReuseIdentifier:#"MyCell"];
And since it's not in a separate nib file, registerNib doesn't seem appropriate either. Any ideas?
Although that may be possible you have several options when designing tableview cells. You can either design it in a separate .xib file or you can use a prototype cell. Below is an example of a separate .xib file. When you use a separate .xib you would use the registerNib method.
Or with a prototype cell in which the cell is automatically registered with the tableView.

Programmatically create instance of UICollectionViewCell from storyboard

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!

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.

How to create a custom header view for a table view section using outlets and IB

I would like to make a custom header view for a table view section in Xamarin.IOS with interface builder. However, I dont want this view to have a static content, instead I would like to create outlets, so I can modify the element's value contained in the view.
I have done custom table view cells before with interface builder (piece of cake), so the question is: is there any way to accomplish this on a section header too?
This is what I want to do:
PD: I'm using monotouch.dialog, and this controller is a DialogViewController
I recommend you to use a UIViewController instead a UITableViewController and put the first part of your design (the user information and the buttons) in a UIView and the restrings section in a UITableView.
It's a better solution than implementing a UITableViewController with multiple headers.
let me know if it works for you.

UITable view interface builder creation

I am building an app using storyboard. I have added a table view to my view controller, chose static cells, and custom, insertea a title and some pictures. I have also linked each row to a view controller, with modal segue. But I want to be able to add, delete, and reorder the rows. So I added the codes. The only thing is that I can not connect the table view to the codes. If I connect the data source, and run the project I see just an empty table view. So, is there a way to create the table view using interface builder, and just a few codes? otherwise if there are to much codes everything gets messed up.
Connect delegate and datasource to ViewController icon in your Storyboard. Then add UITableviewdelegate and UITableviewdatasource in view controller code. When you connect and do this, then tableview will search its delegate and datasource methods in your code and you will get the output which you expect.
If you want to add, delete and reorder the rows, you can't use static layouts, because those operations make the table view not static!
You will have to implement it using datasource methods and dynamic prototypes. It won't be too difficult. You can still build each type of cell in the storyboard, you can have multiple prototypes with different reuse identifiers.

Resources