如何在Swift中使用UISplitViewController

编程入门 行业动态 更新时间:2024-10-15 18:23:07
本文介绍了如何在Swift中使用UISplitViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

所以我将一个 UISplitViewController 添加到一个嵌入了 UITabBarController 的项目中。

UISplitViewController 有一个 UINavigationController 作为Master& ;与自己的根控制器的详细关系。

Master UINavigationController rootController 有一个详细的segue到细节 UINavigationController 。

见这里:

  • 在移动设备上,标签栏上方有一个底栏,我无法弄清楚如何删除。我在iPad上遇到了同样的问题,直到我在 UISplitViewController 扩展 viewDidLoad 中添加了代码,但这并没有影响到移动。见这里,

  • PS:我不确定问题是否太长,我认为最好将所有内容放在上下文中。此外,我一直在做大量的研究,但我找不到任何使用UITabBarController的swift资源。

    我确实按照以下教程 nshipster/uisplitviewcontroller/

    解决方案

    你是如此接近,只需做以下事情。

    使用详细信息segue保持拆分视图布局,并为以下方法返回true,并删除其余代码以使用变量 collapseDetailViewController 。

    func splitViewController(splitViewController:UISplitViewController,collapseSecondaryViewController secondaryViewController:UIViewController,ontoPrimaryViewController primaryViewController:UIViewController) - > ; Bool {返回true }

    将以下内容放入Master View控制器中

    self.splitViewController!.delegate = self; self.splitViewController!.preferredDisplayMode = UISplitViewControllerDisplayMode.AllVisible self.extendedLayoutIncludesOpaqueBars = true

    将 self.extendedLayoutIncludesOpaqueBars = true 添加到您的详细视图控制器,如上一个答案所述。这应该删除视图控制器上出现的栏。

    此外,如果您想要一些额外的功能,如果您希望详细视图在iPad上使用全屏,请添加以下内容。

    navigationItem.leftBarButtonItem = splitViewController?.displayModeButtonItem() navigationItem.leftItemsSupplementBackButton = true

    So I add a UISplitViewController to a project which is embedded with a UITabBarController.

    The UISplitViewController has a UINavigationController as a Master & Detail relationship with their own root controller.

    The Master UINavigationController rootController has a detail segue to the Detail UINavigationController.

    See here:

    All pretty simple right ? Now in the TableViewController I do the following;

    class TableViewController: TableViewController, UISplitViewControllerDelegate { var collapseDetailViewController: Bool = false override func viewDidLoad() { super.viewDidLoad() splitViewController?.delegate = self } override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { collapseDetailViewController = false } // MARK: - UISplitViewControllerDelegate func splitViewController(splitViewController: UISplitViewController, collapseSecondaryViewController secondaryViewController: UIViewController, ontoPrimaryViewController primaryViewController: UIViewController) -> Bool { return false }

    I aslo have a UISplitViewController extension and do the following;

    extension UISplitViewController: UISplitViewControllerDelegate { public override func viewDidLoad() { self.extendedLayoutIncludesOpaqueBars = true } }

    With all this done I get the following problems;

    • When tapping on tableviewcell to segue to detail view the detail view opens within the master left pane when on iPad in landscape instead of the right. I also cannot figure out how to show the Master View as the first view when in Portrait on iPad or on the iPhone. These two problems may or may not be related I am not sure.

    • On Mobile there is a bottom bar above the tab bar that I cannot figure out how to remove. I had the same problem on the iPad until I added the code in the UISplitViewController extensions viewDidLoad however that did not effect the mobile. See here,

    PS: I am not sure if the question is too long, I felt it is best to put everything in context. Also I have been doing lots of research but I cannot find any resources in swift which use a UITabBarController.

    I did follow the following tutorial nshipster/uisplitviewcontroller/

    解决方案

    You are so close just do the following.

    Keep the split view layout with detail segues and return true for the following method and remove the rest of the code to do with the variable collapseDetailViewController.

    func splitViewController(splitViewController: UISplitViewController, collapseSecondaryViewController secondaryViewController: UIViewController, ontoPrimaryViewController primaryViewController: UIViewController) -> Bool { return true }

    Put the following in you Master View controller

    self.splitViewController!.delegate = self; self.splitViewController!.preferredDisplayMode = UISplitViewControllerDisplayMode.AllVisible self.extendedLayoutIncludesOpaqueBars = true

    Add self.extendedLayoutIncludesOpaqueBars = true to your detail view controller as mentioned by the previous answer. That should remove the bar appearing on your view controllers.

    Also if you want some extra functionality add the following if you want your detail view to use the full screen on iPad.

    navigationItem.leftBarButtonItem = splitViewController?.displayModeButtonItem() navigationItem.leftItemsSupplementBackButton = true

    更多推荐

    如何在Swift中使用UISplitViewController

    本文发布于:2023-11-26 22:00:17,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1635367.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:如何在   Swift   UISplitViewController

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!