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

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?

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.

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.

UITableViewController with Storyboard

I have a subclass of UITableViewController.
I overrid initWithCoder so that when the controller initializes it adds five items to the UITableView that it creates by default (I did not create a UITableView in IB because the UITableViewController creates one).
I would like to add a header (with 2 buttons) that I created in Interface Builder to that tableview.
I linked an IBOutlet to the header from Interface Builder and I set it to be the header of the UITableView created at initialization.
The problem is that although I did this I only see the UITableView with the 5 items (displayed corectly) but I don't see the header. It's like it ignores the header from the Storyboard or something like that.
Any idea why?
Thanks.
I just captured one GIF from of my example StoryBoard that you can drag UIView on top of your UItableViewController and make it resize as par your need. pelase check following.
Hope that help to you. After drag view on UITableview you just need to create IBOutlet and make your task complete :D
Drag a uiwebview into right above the tableview's first cell.

iOS Simulator doesn't show prototype cell

I'm currently learning Objective-C by doing tutorials ("the iOS Apprecente")
Now I need to make a checklist
I added in viewController.h
#interface ViewController : UITableViewController
Normal there stands
#interface ViewController : UIViewController
The next is to go to Storyboard place there a TableViewController, give it the name: ChecklistsViewController (Identity inspector > Custom class > class.
I added a label into the first Table view cell. But when I run it there's nothing.
What to do?
Two separate issues here:
The choice of UIViewController with your own IBOutlet for the table view or a UITableViewController is simply a question of whether, in Interface Builder (IB), you added a standard view controller to which you added a table view, or whether you used a table view controller. You use the former if you have other controls on the view in addition to the table view. You'd generally use the latter if the table view is the only thing being presented in that view controller's view. Bottom line, your choice of UIViewController or UITableViewController is dictated by how you added the scene in IB. From your description, it sounds like you went down the UITableViewController approach, which is fine.
In terms of why you're not seeing anything, there are a bunch of possible reasons:
Did you specify the cell identifier for your table view cell prototype? Is it the same identifier you're using in cellForRowAtIndexPath method?
If you manually added a table view to a standard view controller's view, did you specify the view controller as the delegate and dataSource for the table view? Also, did you create an IBOutlet for the table view itself, hooking that up in IB? (If you used a table view controller in Interface Builder, you don't have to do these steps.)
You might want to double-check that the base class for the table view controller was correctly set in IB.
Did you implement all of the UITableViewDataSource methods, notably numberOfRowsInSection? If you don't do that, it will conclude that there are no rows, and no cells will be generated.
You say that you specified the base class for your view controller in IB to be ChecklistsViewController. But in your code snippets, it looks like you're using a custom class called ViewController. Make sure you're using the same UITableViewController subclass for both.

Table view inside view, inside viewcontroller. Best way to do it?

I have a main home screen in my app which I am eventually hoping to contain a table view in the centre. When a button is pressed, the table view flips to a map view.
I would do this as part of the main view, but I want the surrounding area to stay the same. I have dragged a view into the centre of the homepage view controller, and have set up my table view there. How do I access the data in this view?
As far as I'm aware, there is no way of setting a tableviewcontroller to it. Any help would be greatly appreciated.
You can make whatever View Controller is in charge of the views conform to UITableViewDelegate and UITableViewDataSource protocols in your header (.h) file:
#interface YourViewControllerClass : UIViewController <UITableViewDelegate, UITableViewDataSource>
And then implement the appropriate methods in your implementation (.m) file.
If you're using IB, drag the TableView's datasource and delegate outlets to your view controller subclass.

Resources