Interface Builder : cannot assign custom class to table view controller - ios

I am trying to create a simple app for iOS that uses a tab bar controller to present either a map view or a table view. Both the map view and the table view have the same navigation bar button items:
A Logout button on the left, and Refresh, Add New buttons on the right side of the navigation bar. So I have started experimenting the idea of having a parent controller called LocationViewController, which inherits from the UIViewController.
For the table view, I have a controller called TableViewController: LocationViewController, and another controller called MapViewController: LocationViewController.
On the storyboard, I added a set of two buttons (for refresh and add new) to the top header section of each view (very small, may be hard to see). See the image attached below:
There is no problem for me to assign the custom view controller MapViewController to my map view panel, but I cannot find the custom controller class TableViewController in the panel (see the below screenshot)
I found a similar post on stackoverflow, and a reboot solved that problem, which I also tried, but did not solve my problem at all.

You have added youe buttons in the wrong place. I do not know the right name for the bar, but it contains "associated objects". What you want to achieve should look something like this :
Unfortunatelly, you cannot add two UIBarButtonItems to one side of navigation bar via interface builder. You can either drag a UIView instead of UIBarButtonItem to that "slot" and add two UIButtons there, or you ca add multiple buttons from code.
Also, it seems that the name of your question is a bit misleading :) After carefull reread of your post I found the "right" question.
Answer - you have added a UITableViewController in your storyboard, but your class doesn't inherit from UITableViewController. If you want to keep the base class, you will have to make it a "plain" UIViewController and add a UITableView to it. Note, that this way you won't be able to have prototype cells.

You may need to subclass it from UITableViewController. Replace the UIViewController parent class for UITableViewController, like this:
class ViewController: UITableViewController {
Then make sure you selected the View Controller where blue color is all around it and then you can place the name of the class that inherits from UITableViewController.

Related

Can't link my UITableViewController to my nested UITableView

I need to provide some background to explain how I got to where I am. I'm trying to create an interaction that involves different segues (slide up from the bottom, slide in from right) and, as far as I can tell I can't mix these two styles amongst scenes that are embedded in a Navigation Controller because the Show segue will only appear from right to left if I do.
The behavior I want is: Initial View Controller -> Settings (segue from bottom) -> -> detail for selected Setting ('standard' segue from right to left)
I also want to put a navigation bar in the Settings view so I can have a Done button that will close the view (slide out of sight from top to bottom) like this:
Interface builder won't let me add a navigation bar when I'm using a Navigation Controller and without one it looks like this:
So, I tried something from a thread that suggested nesting views. It almost works (the first screenshot above was taken from that code), but it resulted in a new problem. That problem is that I can't link the nested `UITableViewController' to my SettingsTableViewController.swift custom class. It's simply not an option in the dropdown list of classes and so I can't configure my table of Settings options.
Here's the hierarchy I now have based on the suggestion from that thread:
Also, I've confirmed that my SettingsTableViewController.swift is subclassing UITableViewController.
I'm stumped and would really appreciate some help.
If you try this,
Add a UIViewController and a UINavigationController(this automatically comes with a UITableViewController.
For example sake, add a button to the UIViewController, right click and drag to the UINavigationController and setup the segue to the following show in the image.
Add another UIViewController and right click drag from the UITableViewController to the new UIViewController and use a push segue, which you can reference when you do 'didSelectRowAtIndexPath'.
You shouldn't need to connect things, because your UITableViewController is the rootViewController of a UINavigationController. If you use a UITableViewController the only thing you should have in it's hierarchy is the UITableView, if you want other things, you need to use a UIViewController and add a UITableView, but I don't think you need this because you can achieve your requirements with the default options.
Comment if this does not make sense, good luck,

Use XLForm with a toolbar

I want to launch a XLForms view controller as a Form Sheet. I want the controller to have a toolbar at the top and then the XLForm tableview underneath it. How?
The view controller isn't a navigation controller and so I need to add a toolbar at the top (or bottom) where I can add buttons. So how do I do this?
It turns out that this is not too difficult. I just wish that it was documented somewhere.
All the sample code I could find showed the top view controller inheriting from XLFormViewController. In this case, the IB controller only requires a topline view.
I wanted to expand the view controller to have other components in it other than just a "View" object. I wanted a toolbar across the top and a couple of other things.
So, here's how I did it. I'm not sure that this is the best approach but it did work.
Create the View Controller in IB and add all the components you want.
Include a TableView object someone in your design
Go into the "Assistant Editor" and hook the TableView object to the "tableView" object defined in XLFormViewController.h by ctrl-dragging and dropping on the IBOutlet tableView object.
All other controls work as usual.
Important:
Do not treat the tableView object like a regular object. In other words, do not implement UITableViewDataSource and UITableViewDelegate methods.
Hope this helps.

Can not drag and drop UITableViewController into Storyboard

A book I am using is telling me to drag and drop UITableViewController in object library into Main.storyboard, but it's not working. The UITableViewController just rushes back to object library. What's the problem? It works fine with "Table View". I am using Xcode 7.2, and OS X El Capitan.
Please help.
If you can't drag a Table View Controller to IB, then don't do it. Use a Table View instead! They are (mostly) the same.
I guess your book is telling you how to create a simple table view. So let me tell you how to create a simple table view in a view controller.
Of course, you should first drag a view controller to IB. Then add a table view to the view controller. Add the constraints if you want. Then run the app!
You will probably see a few horizontal lines on the screen and you can scroll it. How nice!
Now how do you add contents to the table? Just create a view controller class file and associate it with the view controller you just created. Then make that class conforms to the UITableViewDataSource protocol and add the required methods. Finally, just associate the class with the table view's data source property. I think your book will talk about this in detail.
If you want to know more, visit https://www.youtube.com/watch?v=s78ndDj8K3U&list=PL6gx4Cwl9DGDgp7nGSUnnXihbTLFZJ79B&index=21
You can't drop a view controller on top of another view controller.
(This is why you are able to drop a Table View onto a view controller, but not drop a Table View Controller.)
Instead, drag the Table View Controller to a blank area of the storyboard. It will be droppable, and appear on the storyboard.
Note that Interface Builder changes the appearance of the droppable object to include a + sign when it's over an area where it can be dropped (and added to the storyboard).

trying to hook up UILabels and IBActions in a custom class (Xcode 5)

I am having issues making UILabels and IBAction buttons in custom classes. Xcode seems to not want me to do it. They way I'm trying to do it is through interface builder (storyboard). I have no issue clicking and dragging to make IBOutlets and IBActions using the main View Controller but when I click and drag over to connect them in a custom class it does nothing. Am I only able to make these in the View Controller? I've attached a pic of me trying to drag over to connect my button in the custom class and you can see that nothing pops up. So basically, Are labels, buttons, text fields etc, for the View Controller class only? Thanks for any feedback.
Within interface builder, you will need to make sure your view controller is using your custom class by opening utilities view on the RHS of the IB, selecting the third icon along (please see picture below) and enter your custom class name in the space provided.
Your custom class will need to be a subclass of UIViewController though, like the picture below, not an NSObject for example.
I'm referring to this line within your .h file ...
#interface MyCustomClassViewController : UIViewController
Your custom class needs to match the UI object you are connecting it with. For example if you had UIView object, your custom class would need to be a subclass of UIView, a UINavigationViewController object, a subclass of UINavigationController etc etc.
I hope this helps.
Select your view controller in the stoyboard and go to the identity inspector, make sure the name there is your custom class name.

Implementing A Mail app-like User Interface

I am trying to implement a user interface that is similar to the iPhone's Mail app.
The main screen displays a table. From the table the user can select a cell, at which point the next screen is launched. At the bottom, there is a bar showing a short text and an icon.
The second screen displays the details of the cell. It will also be a table display. The bottom bar shows icons associated to this screen.
What kind of layouts do I use to implement this in Xcode?
1. Do I use a View controller, add a View and embed a TableView and a Toolbar inside that view?
2. Do I use a Table View Controller and add a Table View inside it and use the bottom tool bar that comes with the table view?
In the Table View Programming Guide for iOS, under 'Recommendations for Creating and Configuring Table Views,' it says 'Use an instance of a subclass of UITableViewController to create and manage a table view.' When I use this, the bottom bar can only be fixed or disappear when going back and forth between two screens via segue. That makes me wonder whether I should just use a View controller which is against the recommendation.
Use a UIViewController
Why?
If you are going to display more than a tableView then it is recommended to use a UIViewController for the storyboard.
UIViewController are much more flexible. I guess your confusion comes from the following documentation line:
Use an instance of a subclass of UITableViewController to create and
manage a table view
This does not mean you must to drag and drop a UITableViewController on the storyboard. It means your class need to inherit from UITableViewController or at least implement the deleguate and datasource methods.
You would use UITableViewController only and only if you need to display a tableView.

Resources