本文介绍了ios7 没有 displayModeButtonItem 或 targetDisplayModeForActionInSplitViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 xcode 6 中启动了一个拆分视图项目,并且运行良好.开箱即用,我在纵向模式下得到了一个带有导航按钮(左上角)的拆分视图,以便可以弹出/弹出主视图.

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.

主要问题是它在 iOS7 中不起作用,因为 displayModeButtonItem 和 targetDisplayModeForActionInSplitViewController 仅适用于 iOS8.

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

我已经看到一些应用程序可以实现相同的效果并且可以在 iOS7 中运行,但我不知道如何做到这一点.有没有人有一个很好的例子或解决方法来在 iOS7 中实现这一点.

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.

开箱即用的 xcode 构建了一个只能在 iOS8 中运行的项目,但我想苹果并没有让我完全惊讶.

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.

推荐答案

您仍然可以使用 UISplitViewControllerDelegate 中已弃用的回调函数来添加和删除 UIBarButtonItem 到您的详细信息视图中iOS 7 平台.在您的 UISplitViewControllerDelegate 中实现如下:

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

这篇关于ios7 没有 displayModeButtonItem 或 targetDisplayModeForActionInSplitViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 14:41