I have a simple iPad app with MasterviewController with a tableview and and a DetailViewController containing a UIWebView. Then i dragged and dropped a SplitViewController in my Storyboard, connected it with my Master and Detail controllers. In MasterViewController i am using the following:
- (void) awakeFromNib
{
self.splitViewController.delegate = self;
}
- (BOOL) splitViewController:(UISplitViewController *)svc shouldHideViewController:(UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation
{
return NO;
}
It currently looks like the following:
Everything is working great. What i want to do is to hide and unhide the MasterViewController with a button at the top left side of DetailViewController, just like the iPad Mail app.
I have found some questions related to this problem but they are not creating the SplitView as simply as i am by just dragging it in the Storyboard and writing few lines of code, So don't mark it as duplicate or something like that.
NOTE: Kindly do not suggest using MGSplitViewController or any other third party library. Thanks in advance.
The MasterViewController is embedded inside a navigation controller. While DetailViewController has a top bar manually added on it because it looses the navigation bar at top when the whole things is added in the SplitView. What i know is that i can create an IBAction button on the top bar of DetailView but dont know how to trigger the hide and unhide functionality.
I do it like this in the master view controller (TableController):
#import "TableController.h"
#import "ViewController.h"
@interface TableController ()
@property (strong, nonatomic) NSArray * theData;
@property (strong, nonatomic) UIViewController * detailVC;
@end
@implementation TableController
-(void)awakeFromNib {
self.splitViewController.delegate = self;
self.detailVC = self.splitViewController.viewControllers[1];
}
-(void)splitViewController:(UISplitViewController *)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem {
NSMutableArray *itemArray = [self.detailVC.toolBar.items mutableCopy];
[itemArray removeObject:barButtonItem];
[self.detailVC.toolBar setItems:itemArray];
}
-(void)splitViewController:(UISplitViewController *)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)pc {
barButtonItem.title = @"Master";
NSMutableArray *itemArray = [self.detailVC.toolBar.items mutableCopy];
if (! itemArray) {
itemArray = [NSMutableArray arrayWithObject:barButtonItem];
}else{
[itemArray insertObject:barButtonItem atIndex:0];
}
[self.detailVC.toolBar setItems:itemArray];
}
I added a tool bar in IB to the detail controller, and gave it the IBOutlet, toolBar.
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