使用情节提要在主从应用程序中隐藏 MasterViewController (XCode 4.2)

发布于 2025-01-01 10:19:49 字数 608 浏览 2 评论 0原文

我使用带有故事板的主从模板创建了新的应用程序。我想为用户提供可以在横向模式下隐藏/显示主视图控制器的便利。我在网上找到了几个例子,但没有一个使用故事板和带有导航控制器的主从模板。

我已经实现了 splitviewcontroller willHideViewController & willShowViewController 帮助我在纵向模式下隐藏主视图控制器。我在应用程序委托的 didFinishLaunchingWithOptions 方法中使用下面的代码来最初加载视图,

UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
UINavigationController *navigationController = [splitViewController.viewControllers lastObject];
splitViewController.delegate = (id)navigationController.topViewController;

如果您能给我指出正确的方向,我将不胜感激。

谢谢, 塔潘·德赛

I have created new application using Master-Detail Templte with storyboard. I want to give user facility where they can Hide/Show Master View Controller in Landscape mode. I found few examples on net but none are using story board and Master-Detail template with Navigation Controller.

I have already implemented splitviewcontroller willHideViewController & willShowViewController which help me hide Master View Controller in Portrait mode. I am using below code in didFinishLaunchingWithOptions method of App Delegate to load views intially,

UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
UINavigationController *navigationController = [splitViewController.viewControllers lastObject];
splitViewController.delegate = (id)navigationController.topViewController;

I would appriciate if you can point me right direction.

Thanks,
Tapan Desai

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风吹雨成花 2025-01-08 10:19:49

主视图显示在弹出窗口中,弹出窗口可用于控制主视图的可见性。

所以...按照以下步骤操作:

1) 创建一个属性来保存 popoverController

@property (nonatomic, strong) UIPopoverController *pc;

2) 捕获 SplitViewController willHide 委托调用上的 popoverController

-(void) splitViewController:(UISplitViewController *)svc
     willHideViewController:(UIViewController *)aViewController
          withBarButtonItem:(UIBarButtonItem *)barButtonItem
       forPopoverController:(UIPopoverController *)pc
{
    barButtonItem.title = @"Menu"; 
    id detailViewController = [self.splitViewController.viewControllers lastObject];
    [detailViewController setSplitViewBarButtonItem:barButtonItem];
    self.pc = pc;  //poppver controller
}

3) 最后使用 pc var 关闭弹出窗口

 if (self.pc) {
        [self.pc dismissPopoverAnimated:YES];
    }

The master view is presented in a popover and the popover can be used to control the visibility of the master.

So...follow these steps:

1) Create a property to hold the popoverController

@property (nonatomic, strong) UIPopoverController *pc;

2) Capture the popoverController on the SplitViewController willHide delegate call

-(void) splitViewController:(UISplitViewController *)svc
     willHideViewController:(UIViewController *)aViewController
          withBarButtonItem:(UIBarButtonItem *)barButtonItem
       forPopoverController:(UIPopoverController *)pc
{
    barButtonItem.title = @"Menu"; 
    id detailViewController = [self.splitViewController.viewControllers lastObject];
    [detailViewController setSplitViewBarButtonItem:barButtonItem];
    self.pc = pc;  //poppver controller
}

3) Finally just use the pc var to dismiss the popover

 if (self.pc) {
        [self.pc dismissPopoverAnimated:YES];
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文