Replace the TableView in a SplitViewController - objective-c

I am looking to replace the UITableView in the MasterViewController section of a UISplitViewController. Instead of the UITableView, I want just a View so I can place UIButtons, UILables, etc in it. These buttons would then control what is shown in the DetailView section of the SplitView.
I have asked this question one other place and someone suggested that I create a subclass of the UISplitViewController. This person didn't give much direction, besides retaining the DetailViewController.h, .m, and .xib and editing the MasterViewController.h, .m, and .xib to my liking.
Here are the steps that I have taken:
Created a new project and selected "Master-Detail Application"
Unchecked "Use Storyboard" so I could get at the xib files.
Opened "MasterViewController.xib"
Deleted the "Table View" under "Objects"
Added "View Controller" to "Objects"
Changed "#interface MasterViewController : UITableViewController" To "#interface MasterViewController : UIViewController" in "MasterViewController.h"
Commented out anything under "MasterViewController.m" that was causing problems because they were referencing properties of the TableView, which is no longer there.
Then I get this error: -[UIViewController _loadViewFromNibNamed:bundle:] loaded the "MasterViewController" nib but the view outlet was not set."
Am I on the right track? If I am, could someone help me out with the error I am getting?
Otherwise, if I am going at this wrong, could someone point me in the right direction?
Thanks!

now, with storyboard in the latest Xcode, here's what i have done …
create a new Master-Detail project, and allow storyboard
open MainStoryboard_iPad.storyboard
click on the TableViewController and then delete it
drag in a new plain ViewController
ctrl-click-drag from the navigation controller that is the master view controller to your new ViewController
remove the MasterViewController.h/.m files, and create a new class that is a subclass of UIViewController
take the name of your just created replacement class and place it in the Class name of the Custom Class section of your identity inspector
now, add buttons and wire up the way you want to. if you stick with a single view controller in the detail portion, you should be able to simply refer to the detailViewController directly and fill it as you want; for multiples, you can probably use replace segues.
for iPhone, the steps will be similar. you'll have to ctrl-click-drag from the nav controller to your new ViewController and set up the replacement ViewController.h/.m files in the same way. the segues from your buttons will be push segues, or you can simply call performSegueWithIdentifier:sender: .

Related

linking header and main files to story board xcode

I am pretty new to xcode and for the life of me I cannot figure this one out. I am adding a view controller to a storyboard and I am trying to add a picker to that controller, I have the code in a header and main file I created but how do I link those files to the viewcontroller in my storyboard?
Here is how:
Create a custom UIViewController subclass for your code, eg MyViewController.h and MyViewController.m
in the storyboard drag out a ViewController
(i think you have done both of these steps)
in the Identity Inspector (panel 3 of left-hand side Utilities panels), under 'Custom Class' you should see your class in the scrolling list. Select it.
Then you will want to make links between your picker in the storyboard and your code....

Why I can't drag outlets from a custom UIView Class?

I have a TableViewController With a dynamic cell and a view I added above it.
I've created a UIView class and added it as a custom class for that view ( just like I do with a custom cell) but I can't drag labels etc from that UIView to its .h file. Only to the main TableViewController.h file. Any idea what's the problem?
A table view in a UITableViewController takes up the whole screen, so the view you added is actually in the table view, not above it, so that's why you can connect to the table view controller. If you want to add a view above the table, use a UIViewController instead, and resize the table view so it doesn't take up the whole screen.
I've noticed this too (for an OS X project) in Interface Builder. I'm not sure if it is a bug or not in IB.
What you will have to do is enter the #property declarations in your .h file manually and then you will be able to connect them.

Change a UIViewController to a UITableViewController inside a storyboard?

I've made a view in my storyboard which I've now decided I'd rather display its data via static table cells.
I can't use static table views in a UIViewController (Static table views are only valid when embedded in UITableViewController instances). So, I need to convert my existing UIViewController to a UITableViewController somehow. I've changed the .h file's parent, but that hasn't done it.
Is there another way to get this going? I'd really rather not have to make a new VC in the storyboard and move everything over, it's a big hassle.
I'll add to this, since the question is about how to change a UIViewController into a UITableViewController, and given that this question is over a year old and the original answer, while valid and may or may not have been the only solution at the time, doesn't actually answer the question and is not the only solution.
It IS possible to do this, you just have to set up the table view delegate and datasource outlets in IB, and manually edit the storyboard XML, which sounds scary but is actually very easy.
First, change your class's parent to be a UITableViewController. UITableViewController already adopts the UITableViewDatasource and UITableViewDelegate protocols, so if your class does too you can remove them:
#implementation MyTableViewController : UITableViewController
...
#end
Next, create new referencing outlets on your UITableView for its dataSource and delegate. The easiest way to do this is to control-drag from the UITableView to itself. The popup will give you the dataSource and delegate options.
Lastly, you need to change the storyboard XML. The storyboard file can get pretty big pretty fast. The easiest way to find the scene you are looking for is by setting Storyboard Identifier in the Identity Inspector. To view the XML directly, right click on the storyboard file in the project navigator and select "Open As -> Source Code". Now just search for whatever you set the reuse identifier to earlier. You'll see something similar to this:
<!-- My Table View Controller -->
<scene sceneID="EuE-XX-cCb">
<objects>
<viewController storyboardIdentifier="MY_TABLE_VIEW_IDENTIFIER" ... >
// Lots of other stuff
</viewController>
</objects>
</scene>
All you need to do is change the opening and closing view controller tags
<viewController>
</viewController>
to be tableViewController instead
<tableViewController>
</tableViewController>
That's it! No need to create a new UITableViewController scene or embed a UITableViewController in a container view.
EDIT:
I should also add that the UITableView MUST be the root view. It cannot be embedded inside another UIView.
If you want your static cell table view not to take up the entire screen, then using a container view is the easiest way to go. Start with a regular UIViewController and drag a container view (next to normal UIView in the object list) into its view. Resize it however you want -- the storyboard will automatically provide a view controller connected to this container view with an embed segue. Delete that controller, drag out a table view controller and right-drag from the container view to this table view controller to make a new embed segue. This table view controller can be accessed from the UIViewController with its childViewControllers property (and conversely, you can access the UIViewController from the table view controller with parentViewController if you need to).
What I did, is creating a UITableViewController in IB, open the Storyboard with a text editor, and copy all the nodes inside from the UIViewController to the UITableViewController.
I think that with this way there's less risk of deleting something important.
Before copying the sections objects, make sure that both tableviews (UIViewController and UITableViewController) have the same properties set like: static or dynamic cells, style (plain or grouped), etc.

How to connect a storyboard to a .h and .m

I have in an app a viewController without a .xib, because I want to use with that ViewController a storyboard instead. The problem is that I don't know how to tell Xcode that ViewController2.storyboard is the view of ViewController2.h and ViewController2.m. Anyone knows it?
When you use storyboards, you generally instantiate the view controller inside the storyboard. The big advantage that storyboards have over .xibs is that they model not just the view hierarchy but also the flow from one view controller to the next. So, you'll probably want to either instantiate your view controller in the storyboard where you plan to use it, or else just go back to loading the view from a .xib (which isn't all that different anyway).

Associating a UITableView with a TableViewController

Can anyone describe how it is possible to have a TableViewController with its xib file having a at its root and the uitableview as a subview?
I believe the TVController somehow assumes that UITableView will fill the entire area.
Why is that?
I have a really specific need to build a kind of side and bottom tabbed interface with a UITableView as its main area. Pressing tabs changes the predicate for the fetchedresultscontroller etc etc.
The reason I want this is because of the breadth and depth of the data categories in the data model. I rally need to flatten the menu structure a lot...other wise with a table and navbar controller structure, user experience will be akin to sinking to ever deeper depths of a cavern!
My idea is tried and true in other paradigms...in iOS it almost looks like it's Apple's way or the highway. I am OK with APPLE of course no gripe.
But I really would like to create this.
I tried adding a new tableviewcontroller complete with xib and then removing the UITableView in IB and replacing with a UIView and a UITableView as a subview, hooking up (I believe) the delegate to the file's owner.
I created an IV tableView for when I want to reference it and again used IB to hook it up in IB
Try to run it and it whines that...
[UITableViewController loadView] loaded the "TabbedTableController" nib but didn't get a UITableView.'
Really can't seem to get my head around what the issue is here.
There doesn't appear to be anymore I can do to hook the UITableView up!
Any help would be terrific. I'll send you a Christmas card in desperation :^)
Also...why should it be so and how strict is this UITableView fullscreen thing?
Enlighten me if you can. The docs I have read don't want to.
Regards
Keith
A UITableViewController does assume that the root view (i.e. the controller's view property) will be a UITableView, thus the table view fills the screen. When you need a view that combines UITableView with other top level views, you will need to do a little more work but it's not hard:
Your view controller will not subclass UITableView. Instead, do this:
#interface MyViewController : UIViewController
<UITableViewDelegate, UITableViewDataSource>
#property (nonatomic, weak) IBOutlet UITableView* tableView;
In Interface Builder, drop in a UITableView and whatever other controls you need. The table view can be any size and in any location in the view hierarchy. Also in Interface Builder, ctrl-drag from the table view to your VC and set the delegate and dataSource outlets, and ctrl-drag from your VC to the table view to set the tableView outlet.
Your view controller implementation should be the typical table view controller implementation: cellForRowAtIndexPath, etc.
A UITableViewController is more or less just all of the above work packaged up into a single unit for you.