0

I am very new to iOS development. In my app I have a tab bar and in one of the tabs I have a UISplitViewController. My issue is that when I go to the tab it shows the Detail view first. Then I have to click the back button to get the the master view. I have found one other person having this issue on stackoverflow, but the solution was in Objective-c and I am using the storyboard (not sure how to attach a class to it) and swift, so that did not help.

It also does not work when using an ipad in portrait mode. When I shift to landscape it works fine, but just shows a black screen (no back button) in portrait mode. Any help would be appreciated. Thanks.

I am not sure what other info you need or what you want me to show, so let me know if I left something out.

adjusted 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
}

Update: ended up fixing following this answer Open UISplitViewController to Master View rather than Detail

Community
  • 1
  • 1
Ephraim Schmitt
  • 227
  • 2
  • 16

1 Answers1

0

I have created a sample SplitViewController in the project and set the property in the appdelegate. This works for me https://github.com/harsh62/stackoverflow_TestMasterDetailApp

splitViewController.preferredDisplayMode = .AllVisible

The full function is as follows:

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
}

References: UISplitViewController - set always visible master controller when

Community
  • 1
  • 1
Harsh
  • 2,852
  • 1
  • 13
  • 27
  • thank you. I will try this when I get home and let you know. – Ephraim Schmitt Aug 11 '16 at 17:42
  • I tried the code and got this error Could not cast value of type 'UITabBarController' (0x1024988b0) to 'UISplitViewController' (0x1024a5240). (lldb) – Ephraim Schmitt Aug 13 '16 at 00:48
  • You are setting this property, thats why you are getting this error. Try to set `preferredDisplayMode` on the split controller object. – Harsh Aug 13 '16 at 01:23
  • I created the splitviewcontroller directly in the storyboard, so I don't have a controller class. Where would I change the preferredDisplayMode? – Ephraim Schmitt Aug 13 '16 at 03:05
  • Did you check the github example I made for you? – Harsh Aug 13 '16 at 03:07
  • Yes, I did look at the github example. I realized that the reason your code was crashing at first is that my rootview was not a navigation controller but a tabbarcontroller. So I adjusted the code. But now I am getting an error that it cannot cast my detailController to a UINavigationController – Ephraim Schmitt Aug 17 '16 at 01:38