Can't assign custom UITableViewCell within custom UIViewController - ios

In my storyboard, if I have a UIViewController that inherits from a custom class, can I create a custom class for a UITableViewCell within a tableview inside that UIViewController?
I've tried to do the above, but when I try to connect outlets, I can only drag to the parent ViewController file, and not to the connected TableViewCell file. Why is that?

You can connect outlets of your cell.
You need to assign the class of custom table view cell in storyboard.
Select the table view cell while dragging to connect outlets.

You seem to be asking 2 questions:
"can I create a custom class for a UITableViewCell"?
Yes, you can use a custom class for your UITableViewCell. Simply select the cell and in the class inspector, enter the custom class.
"I can only drag to the parent ViewController"
That's also correct. For static cells, you can link them to outlets in the view controller. Note that for dynamic cells, you'll need to create them in the tableView:cellForRowAtIndexPath: method.

Related

Populate data to UIcollectionview cell created with xib

I have create my custom collectionview cell with its own class. And I will register them programmatically on a UIviewcontroller class.
The problem I facing now is, I will do all the API call on the UIviewcontroller class but how to I populate them on all the cells I want, because each cell class also will have their own data source and delegate extension.
Note: There is a one cell class inside contain another collectionview.
Thanks.

Custom cell class in UITableView with static cells

I have a UITableView with static cells in a Storyboard. The static cells are of a custom class. I would like to wire up the outlets for the cell but it seems like this is not supported?
Wiring the views onto the ViewController works, but is rather messy (there are lots of cells). A workaround would probably also be to tag the views, but also not ideal. Any other ideas?
You cannot control-drag your UIView to the source file. However, you can link up the other way around.
In Storyboard, select your static cell, and setup the Custom Class.
In your custom class, add all the #IBOutlet as you need.
Go back to Storyboard, select your static cell, and in Inspector, select Show the Connections Inspector (the last tab).
Drag the Outlets there to your UIView(s).
If you use "assistant editor", you will see the circle in front of #IBOutlet is now filled (hooked).
have you checked custom class of that UITableViewCell. it should be custom file and subclass of UITableviewCell you are created.

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.

Button inside Cell Table View Swift iOS

I have a custom cell with a button.
When I implement the outlet get me a error.
This is a screen :
It looks like you're trying to add the IBOutlet to the view controller instead of inside the cell.. You need a UITableViewCell class and add there the IBOutlet. I also recommend you to use a verbe for the IBActions method names.
Check this out, if you didn't create a custom UITableViewCell class.
https://www.youtube.com/watch?v=JG_AMY_gSDQ

How to use a TableView inside a UIViewController?

I want to add a simple static TableView to my UIView. So i dragged it into my UIView. Added the TableViewDataSource and Delegate Protocols to my ViewController class. Created an outlet to my tableview and connected the datasource and delegate outlets to the viewcontroller.
But i still get an error message which says that Static table views are only valid when embedded in UITableViewCOntroller Instances ? Any Ideas how to solve this Problem ?
PS: I am using UIStoryboards for designing the UI
Use a containerView (drag one onto your UIView) which will link to a UITableViewController instead. You will use the prepareForSegue method to initialize the table view controller.
Oh, and you might want to accept answers that help you or no one will help you anymore.
If you want static cells, in your Storyboard, click on the tableview, then in the inspector, change the Content from 'Dynamic Prototypes' to Static Cells. You can also segue these cells to a new controller without having to set up data sources and delegates for the table.

Resources