UISplitViewController Hide/Unhide MasterView In Storyboard

前端 未结 1 1107
天涯浪人
天涯浪人 2021-01-05 03:01

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 i

相关标签:
1条回答
  • 2021-01-05 03:38

    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.

    0 讨论(0)
提交回复
热议问题