3

I started a Split View project in xcode 6 and its working great. Out of the box I got a split view that has a navigation button (upper left) when in portrait mode such that the master view can be popped in/out.

Main issue is that it does not work in iOS7 as displayModeButtonItem and targetDisplayModeForActionInSplitViewController are iOS8 only.

I have seen a few apps that achieve that same effect and work in iOS7, yet I have no idea how to do this. Does anyone have a good example or workaround to achieve this in iOS7.

Bummer that out of the box xcode builds a project that will only work in iOS8, but I guess doesn't completely surprise me with apple.

lostintranslation
  • 23,756
  • 50
  • 159
  • 262
  • this is a similar question, but its using a toolbar tno putting that button in the navbar (meaning there is no arrow back) http://stackoverflow.com/questions/16246519/uisplitviewcontroller-hide-unhide-masterview-in-storyboard – lostintranslation Sep 30 '14 at 18:04

1 Answers1

6

You can still use deprecated callback function in UISplitViewControllerDelegate to add and remove UIBarButtonItem to your detail view for iOS 7 platform. Implement as below in your UISplitViewControllerDelegate:

func splitViewController(svc: UISplitViewController, willHideViewController aViewController: UIViewController, withBarButtonItem barButtonItem: UIBarButtonItem, forPopoverController pc: UIPopoverController) {
    if (!self.respondsToSelector(Selector("displayModeButtonItem"))) {
        let navigationController = self.viewControllers.last as UINavigationController
        let detailViewController: UIViewController? = navigationController.viewControllers?.last as? UIViewController
        barButtonItem.image = UIImage(named: "IC_BackChevron")
        detailViewController?.navigationItem.leftBarButtonItem = barButtonItem
    } else {
        // This callback function is depreciated in IOS8. We use displayModeButtonItem.
    }
}

func splitViewController(svc: UISplitViewController!, willShowViewController aViewController: UIViewController!, invalidatingBarButtonItem barButtonItem: UIBarButtonItem!) {
    if (!self.respondsToSelector(Selector("displayModeButtonItem"))) {
        let navigationController = self.viewControllers.last as UINavigationController
        let detailViewController: UIViewController? = navigationController.viewControllers?.last as? UIViewController
        detailViewController?.navigationItem.leftBarButtonItem = nil
    } else {
        // This callback function is depreciated in IOS8. We use displayModeButtonItem.
    }
}
User
  • 31,811
  • 40
  • 131
  • 232
hufeng03
  • 404
  • 5
  • 9