Use XLForm with a toolbar - ios

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.

Related

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).

Interface Builder : cannot assign custom class to table view controller

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.

Do I need a View or a ViewController?

I'm building a custom view with an xib file that contains various subcontrols. I've got some container control that needs to hold my custom view. I'm kind of unclear on whether I need to make a View that somehow loads itself from the xib file, or a ViewController that does this.
However it's done, I'd like my custom view to be reusable, and something that appears in the toolbox in Xcode, along side buttons and textboxes and such, so I can visually design other views containing my custom view.
What is the right way to do this?
Does your component manages other view controllers (like UITabBarViewController does for example)? If yes, make it a subclass of view controller, if not, and it's just a control, like a switch or a fancy button, scroll wheel etc, then make it a subclass of UIView.

iPhone tableview drop-down menu

I have a view controller with a table view in it and several buttons. I would like to add an additional tableview on top of the view like this (or at least what it would look like if anybody wanted to be my friend :-)):
I don't want to just add this as a subview (like here or here)enter link description here since I don't want to check which table view is being used in my tableview delegate and datasource methods. I would rather use a separate view controller.
I don't want to use a picker because I need to display a bit of info with the items in the list.
I have no problem creating the view with the corresponding controller, but how do I add it on top of the current view, just hiding portions of it?
Thanks!
Apple has a sample code of TableView which deals with this issue. https://developer.apple.com/library/ios/#samplecode/TableViewUpdates/Introduction/Intro.html%23//apple_ref/doc/uid/DTS40010139
Above URL is the link to download the sample code from Apple developer library.
Hope it helps.
This might be overly simplistic for your application, but I have found it to be effective when I have had to do something similar.
You can add this 'drop down menu' view controller's view to the main UIWindow of the entire application. You can add a UIGestureRecognizer on the window as well. If the tap is outside of the view, make it fade away and remove it from the view hierarchy.
Initially I simply added logic in my tableview datasource and delegate methods to destingwish between the two tableviews (as suggested by Scott Bossak above. But I have since switched to building my two views in storyboard and adding their view controllers as usual. However, to present the second table view I instanciate it like so:
SecondTableViewContriller *secondTVC = [self.storyboard instanciateViewControllerWithIdentifier:#"secondTVC"];
then add it as a child view controller:
[self addChildViewController: secondVC];
[secondVC didMoveToParentViewController:self];
I then implemented a protocol to pass the information back to the parent view controller once a row has been selected.

Visually modifying a UIToolbar from xcode storyboard

I'm using XCode 4 and storyboarding an application I'm creating, however I cannot visually modify the UIToolbar.
I'm attempting to modify a UIToolbar that is inside of a UITableViewController - however I have to place the UIToolbar out of the correct hierarchy in order to be able to modify it visually. I've tried placing it onto the view controller area but that does not make it show up.
At one point I was able to make it appear below, as it's own object however I was not able to recreate that.
Once I was able to get it to look like this
Your UITableViewController is inside a UINavigationController, which already has its own UIToolbar—you don't need to drag a new one into your view hierarchy. Interface Builder can simulate the toolbar for you under "Simulated Metrics" in the inspector panel.
Once the simulated toolbar is visible, simply drag UIBarButtonItems into it. Use a custom item with a custom view if you need anything more complicated than a button or spacer.
If you need your toolbar items need to be dynamic, you can maintain a reference via IBOutlets without necessarily having them in your view. Then set your UITableViewController's toolbarItems property or call -setToolbarItems:animated: at runtime to display the appropriate items.
See Apple's UINavigationController Class Reference: Displaying a Toolbar.
To answer your question, the visual editor simplifies the setup of most controls, view hierarchies, and delegation patterns, but it's still up to the developer to make sure they check out. The implementation of UITableViewController makes certain assumptions and assertions about its view hierarchy that Xcode does not enforce through the visual editor. Given that your desired view hierarchy is unsupported, I have to assume that the editor's behavior is either undefined or irrelevant. For a workaround, see Maxner's suggestion.
UITableViewControllers only allow one view object, which of course is UITableView. UITableViews are not cooperative for subviewing and they usually push everything into footers or headers. Something like this isn't possible:
-TableController
-Table
-Subview
-Another subview
UITableViewControllers are reduced to this:
-TableViewController
-Table
So you will need to use a UIViewController and declare a UITableView in there. Heres the Hierarchy you should use then:
- ViewController <Table's Delegate & Data Source>
- View
-Table
- Your UIToolbar
In your ViewController.h declare IBOutlet UITableView and connect Data Source and Delegate to the ViewController. Then simply add the UITableView implementations to your .m file and you're good to go.

Resources