How to use a TableView inside a UIViewController? - ios

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.

Related

Convert TableViewController to ViewController

I have started with a TableViewController but now I would like to change from a TableViewController to a ViewController in the storyboard. Is there an easy way to do this? I want to avoid creating a new View scene in the storyboard and copying the code over.
You have to delete the current TableViewController and create a new ViewController.
If you will set an TableView inside, you also must set DataSource/Delegate, and conform with the Table Views protocols in the ViewController Class.
You can do that using ContainerView. Take one UIViewController and add a ContainerView inside it. Control drag from the ContainerView to TableViewController and select EmbedIn. This is the only way to keep existing TableViewController, but you need to move your code from TableViewController to ViewController. Do this only if it is necessary to use TableViewController and you have to display a View outside the TableView.
Just start implementing ViewController protocol and remove TableViewController, TableViewControllerDelegate and TableViewControllerDataSource.
Also remove the methods from the TableViewDataSource and that's it.

iOS Drawer and Header Image within SWRevealViewControllerSeguePushController

Ho can I add header image to SWRevealViewControllerSeguePushController menu in iOS?
For example like material drawer have it for Android:
Can I modify somehow that UI Table View controller to put some custom UI above the menu rows or any other workaround?
Make a seperate UIViewController.
Add your custom views and a tableView to it.
Make the Delegate and Datasource for the tableView your viewController class.
Also i'd recommend making an IBOutlet for your tableView so it acts just like a UITableViewController (which behind the scenes is a just a normal UIViewController with its view being a UITableView and the delegate and datasource for the tableView being the view controller itself.
Yes you can definitely modify. Use any viewcontroller in place of tableviewcontroller.You will be able to add anything on it's view and do whatever you want. Good luck.

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.

set size of tableview in ios storyboard

I want my ViewController to be shared by a tableView and a TextView, where the TextView would appear beneath the TableView. But the TableView insists on taking over the entire scene/screen. How do I set the height of the TableView in the storyboard so I can make room for my TextView? (Please notice that I am not asking for a footer, which is actually what I am trying to change from)
The problem is that you are using a UITableViewController, which means that you get a scene with a full-screen UITableView.
To avoid this, use a normal UIViewController scene and just insert the UITableView into the interface manually (and configure its delegate and dataSource to point to the view controller).
UITableViewController is just a convenience. It doesn't do anything for you that you can't do yourself with a normal UIViewController. And in your situation, it is an inconvenience instead of a convenience.
Add a container view to your ViewController and link to an "external" UITableView instead of the provided UIView that comes with it when your drop it into your storyboard.
Send data via the segue, get it back via a delegate.
This way you can freely design your View with very little headaches.

iOS - Having 2 table views and other elements under one TableViewController

I'm trying to make an interface like this one:
But I get the following error in XCode: Illegal Configuration: Static table views are only valid when embedded in UITableViewController instances
That controller is a subclass of UITableViewController, so I don't really understand what the problem is, any insight?
First of all, I think you're saying that ProfileViewController is a subclass of UITableViewController. If that is the case, the top level view should be a UITableView not just a UIView. And the error does make sense. If you want to create a static table view, it needs to be embedded in it's own UITableViewController, which is what you get when you drag a UITableViewController from the Palette to the storyboard.
Amended to answer question in comments
So starting from scratch. Drag a TableViewController onto your storyboard and change the class to ProfileViewController. That gives you your tableview with the prototype cells. Then drag an empty view to near the top of the TableView. This will add a headerview to the tableView. (Every tableview has a subview for a header and a footer. This is different than the section headers). Now make that header view taller and drag your other elements into it: the segmentedButton, the search field. Drag your UIImage View. then drag another tableview and position it next to the image view.
Now create a subclass of NSObject NOT NSTableViewController like so.
#interface MiniTableViewController : NSObject <UITableViewDelegate, UITableViewDataSource>
And put the datasource and delegate methods for that minitableview in there. Back on the story board, drag an object to the hierarchy change the class to your MiniTableViewController, and connect the delegate and datasource outlets from your minitableview to the MiniTableViewController in the hierarchy. Make sure you're using the assistant view. Then ctrl-drag from the MiniTableViewController object to the ProfileViewController.h (right before #end) and create an IBOutlet. Now you can access your new custom object from ProfileViewController. You can also create an IBOutlet in MiniTableViewController and connect it to ProfileViewController if you need MiniTableViewController to send messages to ProfileViewController.
A UITableViewController can only have one Table View. You have two. You have to find another way to do it.
Have you put a UITableView in your xib ?
If yes, have you bind this UITableView to your controller?

Resources