UISplitViewController in quick navigation from DetailView

I am trying to create a MasterDetail application in Swift and it works well on iOS8 Simulator. However, when I tried this on my iPad iOS 7.1, I got this error:

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

This is in my AppDelegate.swift file (generated by Xcode, I haven’t added anything):

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
}

The problem arises from this line where the left button is created:

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

When I delete this line, it runs on iOS 7, but only the DetailView is displayed. When I scroll the left edge, MasterView does not appear (it is on the iOS 8 simulator), and basically there is no navigation to MasterView

If anyone has the same problem?

Thank!

+4
source share
2

UISplitViewControllerDelegate UIBarButtonItem IOS7. 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.
    }
}
+2

. displayModeButtonItem IOS IOS 8. , IOS 8, Ipad IOS 7.1. ( ), IOS 8 Ipad. .

0

All Articles