Convert TableViewController to ViewController - ios

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.

Related

How to access programmatically a tableview added with storyboard

I added a tableview to my viewcontroller using the storyboard. What is actually happening behind the scenes? If a UITableview object gets created how can I access this object programmatically? What is the name of the instance? Is it a property of my viewcontroller object?
More specifically, what I need to do is force my tableview to refresh (from inside of my viewcontroller). I read in other posts that I should be able to do something like this [self.tableview reloadData]. I can't do this because my viewcontroller does not have a property called "tableview" (or anything similar)
Control + click and drag your tableView into your header file to create an IBOutlet
Set the delegate and data source by control click and drag from your table view to your view controller - make sure both dots are seen. Now
In the interface .h file add the delegate and datasource as such:
#interface HomeTableViewController : UIViewController
<UITableViewDataSource, UITableViewDelegate>
Now your view controller should have access to the methods needed to use [self.tableView reloadData]
try this simple table view
and this work with custom tableview cell
try above tutorials and in your case to use [self.yourtablviewname reload]
you have to create an outlet of your table view and use it.
Remember that the storyboard defines a collection of objects which are created when you make an instance of say, a ViewController.
You are on the right track, you need to define variables in your view controller which are references to the objects in the storyboard. You mark them as IBOutlet in your code. You then 'connect' them to the objects in the storyboard. Right click on the viewcontroller in the storyboard and you will see the variables which have been designated as IBOutlet listed as 'outlets'. You can drag from the popup table to the objects in the storyboard to connect them. Now, when an ViewController is created, all the IBOutlet variables are set to point to the various objects (tables, text views etc) in the instance just created.
Remember that the 'connect' you do with the Interface Builder, happens at rum time when you create an instance of the object in IB.

How to add UITableView to UIView which is already a subview?

I have specific situation for which I haven't found solution.
I'm doing over storyboard. So I have ViewController on which I'm using segment control for switching subviews. Every subview is ViewController but one of them is using table view. So basically it's like this:
HomeViewController
FavoritesViewController
Table View (with custom cell)
GalleryViewController
How to properly set up this? Should I rename/refunction FavoritesViewController to FavoritesTableViewController or?
If there is any other question, please ask it.
UPDATE 1:
FavoritesViewController is having just UIView in UI because I don't need whole UIViewController
Create an IBAction from the segmented control. Inside the handling method, use "ViewController containment" to switch between two view controllers.

how to place a UIViewController in another UIViewController through nib in xcode

I have developed a DetailViewController, derived from UIViewController. Now I want to use this DetailViewController inside another InfoViewController's layout. I found one way to do this by using addSubView method. But what I am looking for is to plot it through nib file, like other UIViews. I want to plot DetailViewContoller inside InfoViewController's layout through nib file. Is this possible?
Any response will be thankful.
Yes it is possible..
First remove the referencing outlet for view in DetailViewController.xib.
And in InfoViewController.xib drag-drop Object and edit the custom class to DetailViewController.
Now drag-drop view in InfoViewController.xib and add what ever subviews you want to it. Now add new view referencing outlet to DetailViewController which is under objects.
Hope this will help you.

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.

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