gpt4 book ai didi

objective-c - 从 DetailView 快速导航中的 UISplitViewController

转载 作者:搜寻专家 更新时间:2023-10-31 19:35:31 25 4
gpt4 key购买 nike

我正在尝试在 Swift 中创建一个 MasterDetail 应用程序,它在 iOS8 模拟器上运行良好。然而,当我在我的 iOS 7.1 iPad 上尝试时,我得到了这个错误:

**Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-    [UISplitViewController displayModeButtonItem]: unrecognized selector sent to instance**

这是在我的 AppDelegate.swift 文件中(由 Xcode 生成,我没有添加任何内容):

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
let splitViewController = self.window!.rootViewController as UISplitViewController
let navigationController = splitViewController.viewControllers[splitViewController.viewControllers.count-1] as UINavigationController
navigationController.topViewController.navigationItem.leftBarButtonItem = splitViewController.displayModeButtonItem()
splitViewController.delegate = self

let masterNavigationController = splitViewController.viewControllers[0] as UINavigationController
let controller = masterNavigationController.topViewController as MasterViewController
controller.managedObjectContext = self.managedObjectContext
return true
}

问题出在创建左按钮的这一行:

navigationController.topViewController.navigationItem.leftBarButtonItem = splitViewController.displayModeButtonItem()

当我删除此行时,它在 iOS 7 上运行但仅显示 DetailView。当我从左边缘滑动时,MasterView 不会出现(在 iOS 8 模拟器上会出现)并且基本上没有到 MasterView 的导航

有人遇到同样的问题吗?

谢谢!

最佳答案

您仍然可以在 UISplitViewControllerDelegate 中使用已弃用的回调函数来添加和删除 UIBarButtonItem 到您的 IOS7 平台的详细 View 。在您的 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_BackArrow")
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.
}
}

关于objective-c - 从 DetailView 快速导航中的 UISplitViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25660122/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com