UISplitViewController在Storyboard中隐藏/取消隐藏MasterView [英] UISplitViewController Hide/Unhide MasterView In Storyboard
问题描述
我有一个简单的iPad应用程序,带有带有tableview的MasterviewController和一个包含UIWebView的DetailViewController。然后我在我的Storyboard中拖放了一个SplitViewController,将它与我的Master和Detail控制器连接起来。在MasterViewController中,我使用以下内容:
- (void)awakeFromNib
{
self.splitViewController。代表=自我;
}
- (BOOL)splitViewController:(UISplitViewController *)svc shouldHideViewController:(UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation
{
return NO;
}
目前看起来如下:
一切都很好。 我想要做的是使用DetailViewController左上角的按钮隐藏和取消隐藏MasterViewController,就像iPad Mail应用程序一样。
<我发现了一些与此问题相关的问题,但他们并没有像我一样只是在Storyboard中拖动它并编写几行代码来创建SplitView,所以不要将其标记为重复或类似的东西。
注意:请不要建议使用MGSplitViewController或任何其他第三方库。在此先感谢。
MasterViewController嵌入在导航控制器中。虽然DetailViewController上面有一个手动添加的顶栏,因为当在SplitView中添加全部内容时,它会丢失顶部的导航栏。我所知道的是,我可以在DetailView的顶部栏上创建一个IBAction按钮,但不知道如何触发隐藏和取消隐藏功能。
我在主视图控制器(TableController)中这样做:
#importTableController.h
#importViewController.h
@interface TableController()
@property(强,非原子)NSArray * theData;
@property(强,非原子)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];
}
我在IB中添加了一个工具栏给细节控制器,并给了它IBOutlet,toolBar。
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.
这篇关于UISplitViewController在Storyboard中隐藏/取消隐藏MasterView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!