我在xcode 6中启动了一个Split View项目,它的工作效果非常好。开箱即用的我在纵向模式下有一个带有导航按钮(左上角)的分割视图,这样就可以弹出主视图。
主要问题是它在iOS7中不起作用,因为displayModeButtonItem和targetDisplayModeForActionInSplitViewController只是iOS8。
我见过一些可以达到同样效果但在iOS7中工作的应用,但我不知道如何做到这一点。有没有人有一个很好的例子或解决方法来实现这一点在iOS7。
Bummer开箱即用xcode构建了一个只能在iOS8中运行的项目,但我想苹果并不会让我感到惊讶。
答案 0 :(得分:6)
您仍然可以在UISplitViewControllerDelegate
中使用已弃用的回调函数来添加和删除UIBarButtonItem
到iOS 7平台的详细信息视图。在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.
}
}