Ios7 no displayModeButtonItem or targetDisplayModeForActionInSplitViewController

I started a Split View project in xcode 6 and it worked great. Out of the box, I got a split view that has a navigation button (top left corner) in portrait mode so that the master view can be inserted / withdrawn.

The main problem is that it doesn't work in iOS7 as displayModeButtonItem and targetDisplayModeForActionInSplitViewController are iOS8 only.

I've seen several apps that achieve the same effect and work in iOS7, but I have no idea how. Does anyone have a good example or workaround to achieve this in iOS7.

Bummer, which out of the box xcode creates a project that will only work in iOS8, but I guess it doesn't quite surprise me with an apple.

+3


source to share


1 answer


You can use the legacy callback function in UISplitViewControllerDelegate

add and remove UIBarButtonItem

to your detail view for the iOS 7 platform. As shown below in 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.
    }
}

      

+6


source







All Articles