I've got a SplitView template project. I want to change DetailView on user selecting item in RootViewController.
In fact I can't just change what's inside that view (DetailView) like it's done in the template (when you check "use core data storage" on creating project). I want to switch between whole views.
I've tried that:
AppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
[appDelegate.detailViewController setView:curretnDetailViewController.view];
appDelegate.detailViewController = currentDetailViewController;
By the way I don't understand why do I need line#2 (..setView:..)? Why assigning detailViewController (line#3) is not enough? - Code looks awful=(
But anyway that doesn't work exactly as I want. Everything except detailView disappears. Like I've changed the main view, not just DetailViewController's
I guess I should change something in splitViewController but didn't find out what=(
Thanks for your attention.
I too had your questions about a week ago and I too got little help in this forum. I hope I can change that for you.
First did you know apple has a Multi Detail View example? It is here Apple Examples
You have to understand what a splitviewcontroller is to get the idea of what Apple is doing. Think of the splitview controller as a container within your device window. This container has 2 compartments, a thin left hand side a bigger right hand side. Now to change over either side you have to replace this compartment with another compartment of similar size and nature. You cannot put in there a compartment that does not fit or that does something fancy cause it will simply not fit.
In technical talk find this below code in the example. The splitview controller has an array of 2 views and you can change the views in this array. Thus in this array is 2 views the left is called navigationcontroller and the right is detailviewcontroller. If you alloc and initiate a view and add it to either of these two then this view will replace the current view in the splitviewcontroller.
NSArray *viewControllers = [[NSArray alloc] initWithObjects:self.navigationController, detailViewController, nil];
splitViewController.viewControllers = viewControllers;
Now to your second part to your question - which I think is from the left hand side you want to be able to always be able to choose something and be able to change the right hand side....am I right?
I have read three different ways of doing this and not seen anyone who says one is better than the other.
I am not an expert so I have not added code for each of the 3 choices above, what I suggest is that you do a little bit of googling for the topics and you will see examples. If you get really stuck on one let me know and I will try to find again with google the examples that I have found in the past. The least complicated I think is No.1.
I hope this get you going in the right direction.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With