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

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.

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.

Embedding TableView in TableViewController into another view

I would like to customize content of table view controller(add some buttons, etc.) but root view for that is table view. Is it a way to embed it into another view and add controls on it?
You can use Container View.
In the storyboard create another view controller that you would use to host those controls. Then drag in Container View from the Object Library (normally the last item in the list) and place it where you want the table view to appear (which could be the whole screen). Doing this, the Container View will create another view controller. Simply delete that and ctrl drag from the Container View to your table view controller and select embed segue.
By doing this, you would not have to change anything in your current table view controller if it doesn't depend on other view controllers to give it data in order for it to work. If it does, however, you could assign the segue identifier to the embed segue, implement prepareForSegue:sender: and do whatever you would normally do with other segues.
You simply add TableView as a subview of a uiviewcontroller. Remember to call for delegates. Normally i don't use storyboards, but if you do it programmatically you can do like this:
On .h file:
#interface EmbeddedTableView : UIViewController <UITableViewDelegate, UITableViewDataSource>
And on .m file simply create your tableView by adding it as subview of viewcontroller.
You can look at this for example: How to set up UITableView within a UIViewController created on a .xib file

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.

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