I've developed an app that, on iPad, has a UISplitViewController. The master view is a tableview embedded in a NavigationController. The detail is not in a NavigationController (and I do not want it to be). I've added a button to the detail that I want to show/ hide the master view. I want the app to run on iOS 7.0 and later. How could I call the master view from button click in detail view?
Asked
Active
Viewed 1,253 times
2 Answers
1
First, override the following delegate method:
- (void)splitViewController:(UISplitViewController *)splitController willHideViewController:(UIViewController *)viewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)popoverController
and use it to grab a reference to the bar button item, and store it in an iVar:
barButtonForMaster = barButtonItem;
Then, when you want to show the master view controller, make a call like this:
[barButtonForMaster.target performSelector: barButtonForMaster.action withObject: barButtonForMaster];
In case you want to perform this right at the start, then use some delay in order to prevent app crashing (thanks to the helpful comment):
[barButtonForMaster.target performSelector: barButtonForMaster.action withObject: barButtonForMaster afterDelay:1];
In that case you can perform the selector right in the split view delegate method.
![](../../users/profiles/785593.webp)
David 'mArm' Ansermot
- 5,742
- 6
- 40
- 77
-
thanks, but really what I was asking for is the code for myMethodToShowHideMaster – MSU_Bulldog Oct 22 '14 at 16:42
-
This would work if my detail view was embedded in a Navigation Controller, but it is not. I am using a UIButton on the detail view, not a UIBarButtonItem. Could you update your answer for a UIButton without the use of a Navigation Controller – MSU_Bulldog Oct 22 '14 at 18:19
1
I found a tutorial that answered my question. You can find it here: http://www.dharmaworks.net/Consulting/switching-detail-views-in-uisplitviewcontroller-with-ios7/
![](../../users/profiles/3543861.webp)
MSU_Bulldog
- 3,465
- 5
- 34
- 73