UISplitViewController首先显示详细视图

时间:2016-08-11 02:05:20

标签: ios swift uisplitviewcontroller

我是iOS开发的新手。在我的应用程序中,我有一个标签栏,在其中一个标签中我有一个UISplitViewController。我的问题是,当我转到选项卡时,它首先显示详细信息视图。然后我必须单击后退按钮才能获得主视图。我发现另一个人在stackoverflow上有这个问题,但是解决方案是在Objective-c中,我正在使用故事板(不知道如何将类附加到它上面)和swift,所以这没有帮助。

在纵向模式下使用ipad时,它也不起作用。当我转移到横向它工作正常,但只是在纵向模式下显示黑屏(没有后退按钮)。任何帮助,将不胜感激。感谢。

我不确定您需要的其他信息或您希望我展示的内容,因此,如果我遗漏了某些内容,请告诉我。

调整appdelegate

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Override point for customization after application launch.
    let tabBarController = self.window!.rootViewController as! UITabBarController
    let splitViewController = tabBarController.viewControllers![3] as! UISplitViewController

    ///////////////////Always visible property
    splitViewController.preferredDisplayMode = .AllVisible
    ///////////////////
    let navigationController = splitViewController.viewControllers[splitViewController.viewControllers.count-1] as! UINavigationController
    navigationController.topViewController!.navigationItem.leftBarButtonItem = splitViewController.displayModeButtonItem()
    splitViewController.delegate = self
    return true
}

更新:按照此回答Open UISplitViewController to Master View rather than Detail

结束修复

1 个答案:

答案 0 :(得分:0)

我在项目中创建了一个示例SplitViewController,并在appdelegate中设置了该属性。这适用于我https://github.com/harsh62/stackoverflow_TestMasterDetailApp

splitViewController.preferredDisplayMode = .AllVisible

完整功能如下:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Override point for customization after application launch.
    let splitViewController = self.window!.rootViewController as! UISplitViewController
    ///////////////////Always visible property
    splitViewController.preferredDisplayMode = .AllVisible
    ///////////////////
    let navigationController = splitViewController.viewControllers[splitViewController.viewControllers.count-1] as! UINavigationController
    navigationController.topViewController!.navigationItem.leftBarButtonItem = splitViewController.displayModeButtonItem()
    splitViewController.delegate = self
    return true
}

参考文献: UISplitViewController - set always visible master controller when