ios - splitviewcontroller inside tabbarcontroller using storyboards - objective-c

I have my app mapped out using storyboards where there is an entry screen that segues to a tabbarcontroller which contains 3 tabs. Each tab contains a splitviewcontroller and I have written classes for each master and detail view controller. The bit I'm not sure on is how to give each masterviewcontroller (that controls the table on the left hand side) a reference to the detailviewcontroller.
I can see in the attributes inspector there is an identifier field, should i put something in here for the detailviewcontroller (e.g. 'detailviewcontroller1) and then somehow get that object by it's instance name in code?

Both your master and detail view controllers will have a property, splitViewController, that holds a pointer to the split view controller.
The split view controller has a property, viewControllers, which holds an array of the view controllers contained in the split view. This array will always contain 2, and only 2, view controllers - at index 0 is the master controller, and at index 1 is the detail controller.

So your SplitViewController should be connected to 2 segues that connect two separate UINavigationControllers (one for Master and one for Detail). These two nav controllers will connect to your two VC's (Master and Detail).
You will then create a property for that detail VC inside the master VC and pass whatever data you need to when the user selects a row from the TV.
If you need to see how this is supposed to be layed out and wired up, just create a new iPad application using the Master-Detail template.

Related

Selecting rows in NSTableView inside a container view

In my interface I need to provide two NSTableViews in the same window that are structurally the same, but present different data to the user. I'm using storyboards and to do this, I've placed two Container Views in the view controller of the window. I then added a single view controller to the storyboard (outside of the window's view controller) and into that controller placed an NSTableView.
A couple of storyboard screenshots to illustrate:
The NSTableView is inside the Lineup View Controller, which has its own interface and implementation. The two Lineup View Controllers are binded to the container views within viewDidLoad of the Game Board View Controller like so (showing the code for only one of the attachments):
homeLineupView = [self.storyboard instantiateControllerWithIdentifier:#"Lineup View"];
[self addChildViewController: homeLineupView];
[HomeLineupContainerView addSubview:homeLineupView.view];
I'm able to successfully populate the two table views using notifications to provide the data that is unique to each table. The table views are functioning independently, as expected, with no problems.
Where I'm kind of stuck is how I now go about talking to the two table views from the view controller that manages everything else in the window (Game Board View Controller in the second figure). For example, how would I go about telling the table view inside Home Lineup Container View to select row 3? I have references to the Lineup View Controllers, but not the NSTableViews — unless there is a straightforward way to get those so I can call the methods directly. Or... do I need to set up notifications (or some other mechanism) for doing things like selecting a row, detecting a double click, etc?
Thanks!!
Adding a little more information about where I am confused
When I step through my code in the debugger I can "see" the table view inside the NSViewController that references the enclosing container view (see below).
You can also see my very incorrect attempt at using tableView directly to selectRowIndexes. 'visitorLineupView' is defined like so:
#interface GameBoardViewController : NSViewController <NSOpenSavePanelDelegate> {
:
:
NSViewController *visitorLineupView;
NSViewController *homeLineupView;
:
:
}
And the tableview itself is defined like so:
#interface LineupViewController : NSViewController <NSTableViewDataSource> {
:
:
IBOutlet NSTableView *tableView;
:
:
}
So, the procedural C programmer in me sees all this and wants to grab that 'tableView' pointer and use it directly to send it 'selectRowIndexes' message. But I know that conceptual rules of MVC are throwing up roadblocks I'm having a difficult time scaling.

Showing Toolbar on 2nd ViewController

I have two view controllers on the same storyboard. What I want to do is send an array of string values to the table view control on another view controller.
ViewController2 *second=[self.storyboard instantiateViewControllerWithIdentifier:#"View2"];
second.arrayFromVC1=areaArray;
[self presentViewController:second animated:YES completion:nil];
The second view controller has a toolbar control at the top by default. (See below.)
Passing data to another view controller wasn't easy for me, who has been using Xcode for two weeks. I somehow managed it. So an array of strings is sent to the 2nd view controller through an array variable (arrayFromVC1) set on the 2nd implementation file. I suppose experienced Xcode users know what I'm talking about. Anyway, the 2nd view controller does receive a list of values as shown below.
Well, the problems are that the toolbar control on the 2nd view controller will disappear when the user gets to see the list and that the table view control (UITableView) occupies the entire window. I understand that you can control the size of the table view control by specifying values under the viewDidAppear method. But my question is... Is that how things work with iOS and Xcode? So if I want to display that toolbar control at the top, I have to do it programmatically by writing code under the viewDidAppear method as well?
Thank you for your advice.
Tom
Tom, are you using interface builder and storyboards? If so, select the ViewController in IB, go to Editor (in the top menu) --> Embed In --> Navigation Controller.
This will embed the chosen VC and any VC it segues to (and so on) into a Nav Controller.

Make a view whose contents appear across all storyboard scenes

My app is made of 2 storyboard cenes, but these have a mutual UILabel whose value shouldn't change with the change of the scene, (as it does now) so I was thinking of moving this label to a view that would be on both controllers, how can this be done?
You would simply have an outer ViewController with the label in it's view. Two more view controllers have the scenes, and their views are subviews of the outer view controller.
Perhaps the inner view controllers use a navigation controller, or whatever is appropriate for your needs.

Add other objects to iOS 5 storyboard after tableview

I have a simple iOS 5 storyboard that contains a tableview controller scene. However, the table UI takes up 100% of the real estate and I am unable to add any additional objects such as a title bar. Any object that I drag to the scene will try to size correctly and what-not but as soon as I let go it will not add the object. What am I doing wrong?
If all you want is a title bar, then it looks like you want to embed your table view controller in a navigation controller. You can do this by selecting your table view controller and using the Editor: Embed In: Navigation Controller menu command. Once you do this, you should have a navigation bar, and you can double click it to edit the title.
If you need arbitrary UI elements along with your table view, then I think you need to use a plain UIViewController scene instead of a UITableViewController, and manually drag a UITableView into the scene. Your view controller would not subclass UITableViewController, instead it would subclass UIViewController and implement the UITableViewControllerDelegate and UITableViewControllerDataSource protocols. Also, you would need to manually wire up the delegate and dataSource outlets by ctrl-dragging from the table view to your view controller in interface builder, and your view controller would need a custom tableView outlet that points to the UITableView and is correctly wired up in IB. Perhaps there is a simpler approach than this though, if someone has a better suggestion that would be great to hear.

iOS Split View - Load XIB

I am new to making iOS apps. I want to make a Split View app so I can have topics on the left and the content on the right.
I want to be able to pull the xib file and display it on the right. How can I do this?
I have a basic one working where it changes image, but not views. I want to display the xib file relating to the selected one in the array. Any tutorial to show me how to do this would be great.
Here is the video I watched.
P.S I am new to this app development. Thanks.
A split view controller manages two view controllers.
When you create a view controller, you can specify the .xib file from which it should load its view.
It follows, then, that when the user taps on a topic, your code can create a corresponding view controller (see UIViewController's -initWithNibName:bundle: method) and set that view controller as the split view controller's detail view controller.
It's possible to have an existing view controller load a new view from a .xib using NSBundle's -loadNibNamed:bundle:owner: method, but that's usually more work with no real advantage over replacing the entire view controller.
As far as I remember, you should have access from your viewController to the property splitViewController, on which you can change the property "viewControllers" to any array containing the rootViewController at index 0 and the detailViewController (set to your new detailViewController) at index 1.
If you don't want to have sveral controller for your views, I remember having used NSBundle methods to load a nib file and assign it to a controller. I believe this is another possibility but you have to test it.