在折叠显示中以编程方式关闭详细视图控制器? [英] Programmatically dismiss detail view controller in collapsed display?

查看:24
本文介绍了在折叠显示中以编程方式关闭详细视图控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 UISplitViewController 折叠显示中,如何以编程方式返回主视图控制器?

In a UISplitViewController collapsed display, how can I programmatically get back to master view controller?

我用谷歌搜索但没有找到解决方案.不确定我是否使用了正确的关键字.这是我显示详细视图控制器的方式:

I googled it but found no solution. Not sure if I was using the right keyword. This is how I show the detail view controller:

[self showDetailViewController:[[UINavigationController alloc] initWithRootViewController:detail] sender:self];

我也分别尝试了这三种方法,但都没有奏效:

I also tried these 3 methods respectively, but none of them worked:

if (self.splitViewController.collapsed) {
        UIBarButtonItem *backButtonItem = self.navigationItem.leftBarButtonItem;
        (1):[backButtonItem.target performSelector:backButtonItem.action];
        (2):[[UIApplication sharedApplication] sendAction:backButtonItem.action to:backButtonItem.target from:nil forEvent:nil];
        (3):objc_msgSend(backButtonItem.target, backButtonItem.action);
}

导航项设置如详细VC viewDidLoad:

navigation items set like thie in detail VC viewDidLoad:

self.navigationItem.leftBarButtonItem = self.splitViewController.displayModeButtonItem;
self.navigationItem.leftItemsSupplementBackButton = YES;

推荐答案

我希望做完全相同的事情,这段代码对我有用.我把它放在详细视图中,连接到导航栏中的一个按钮.

I was looking to do exactly the same, and this code worked for me. I put it in the detail view, hooked up to a button in the navigation bar.

在我的应用程序中,详细信息视图可以多次自我隔离,并且无论深入到多深,此代码都会返回主视图.

In my application the detail view can segue to itself a number of times and this code gets one back to the master view no matter how deep down the line it gets.

@IBAction func unwindSegueId(sender: AnyObject) {
    if (self.splitViewController!.collapsed) {
        self.splitViewController!.viewControllers[0].popToRootViewControllerAnimated(true)
    }
}

这篇关于在折叠显示中以编程方式关闭详细视图控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆