简体   繁体   English

iOS-不使用UIBarButtonItem使用委托方法即可显示/隐藏UISplitViewController

[英]iOS - Show/hide UISplitViewController without using delegate methods with UIBarButtonItem

I'am trying to develop a multi-orientation app for iPad's. 我正在尝试为iPad开发一个多方位应用程序。 At landscape mode, the MasterViewController should always visible and I don't have any problem on that. 在横向模式下,MasterViewController应该始终可见,对此我没有任何问题。 But at portraid mode, I have to create a show/hide method. 但是在portraid模式下,我必须创建一个show / hide方法。 The main problem is, I cannot use delegate methods which are 主要问题是,我不能使用委托方法

-(void)splitViewController:(UISplitViewController *)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)pc -(void)splitViewController:(UISplitViewController *)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)pc

and

-(void)splitViewController:(UISplitViewController *)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem -(void)splitViewController:(UISplitViewController *)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem

Because my detailViewController is not a NavigationController and shouldn't be. 因为我的detailViewController不是NavigationController,也不应该是。 Also detailViewController cannot have a NavigationItem. 同样,detailViewController不能具有NavigationItem。 Let me explain why: 让我解释一下原因:

I want my all pages have a dashboard-like views at the bottom of the screen. 我希望我的所有页面在屏幕底部都具有类似于仪表板的视图。 So I never change detailViewController. 所以我从不更改detailViewController。 At the top of the screen, I have a Navigation Controller embedded in a container view. 在屏幕顶部,我在容器视图中嵌入了一个导航控制器。 So If you selected one of the MasterViewController's tableview items, the NavigationController's rootViewController is changing. 因此,如果选择了MasterViewController的tableview项之一,则NavigationController的rootViewController会发生变化。 That's why I cannot have a Navigation item in detailViewController. 这就是为什么我不能在detailViewController中有一个导航项。

These rootViewControllers have buttons which are passing their states to detailViewController wia a custom delegate method. 这些rootViewControllers具有将其状态通过自定义委托方法传递给detailViewController的按钮。 And this method have to hide/show masterviewcontroller. 而且此方法必须隐藏/显示masterviewcontroller。

I don't want to create some custom views and/or animations or custom popover to achieve this. 我不想创建一些自定义视图和/或动画或自定义弹出窗口来实现此目的。 Can anyone help me? 谁能帮我?

Detail View Controller Does not need to be UINavigationController to be delegate to split view. Detail View Controller不需要是UINavigationController即可委派给拆分视图。

You can have set DetailViewController as delegate for the UISplitViewController . 您可以将DetailViewController设置为UISplitViewController委托。 When the split view will hide the view (portrait) save the popover, which you can later show if needed. 当拆分视图将隐藏视图(人像)时,保存弹出窗口,以后可以根据需要显示该弹出窗口。

Users might still show it without any button to - with swipe from left side of screen. 从屏幕左侧滑动,用户可能仍会显示它而没有任何按钮- If it's enough for your app then you don't need to implement the delegate methods. 如果对于您的应用程序来说足够了,那么您就不需要实现委托方法。

// In App Delegate or Nib:
splitViewController.delegate = detailViewController;




// In Detail View Controller :

- (void)splitViewController:(UISplitViewController*)svc
     willHideViewController:(UIViewController *)aViewController
          withBarButtonItem:(UIBarButtonItem*)barButtonItem
       forPopoverController:(UIPopoverController*)pc {


    self.popoverController = pc;

    // Update ui 
    ...
 }


 - (void)splitViewController:(UISplitViewController*)svc
     willShowViewController:(UIViewController *)aViewController
  invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem {

  self.popoverController = nil;
}


- (void)showMenu {
  [self.popoverController presentPopoverFromRect: ...]
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM