2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

iOS8:UISplitViewControllerのMasterViewにUITabBarController追加する

Last updated at Posted at 2014-10-15

##概要
UISplitViewController の MasterView に UITabBarController を追加した所、iPhone でUITableViewController のセルをクリックして DetailView への遷移がプッシュではなくモーダルで表示されてしまうので解決方法のメモです。

##StoryBoard の設定
ios8_tabnavi.png

##下記コードを AppDelegate.swift へ追加

    func splitViewController(splitViewController: UISplitViewController, showDetailViewController vc: UIViewController, sender: AnyObject?) -> Bool {
        if splitViewController.collapsed {
            let primaryTab = splitViewController.viewControllers.first as! UITabBarController
            let primaryNavi = primaryTab.selectedViewController as! UINavigationController
            let detailNavi = vc as! UINavigationController
            if let detail = detailNavi.topViewController {
                primaryNavi.pushViewController(detail, animated: true)
            }
            return true
        } else {
            return false
        }
    }
    
    func splitViewController(splitViewController: UISplitViewController, separateSecondaryViewControllerFromPrimaryViewController primaryViewController: UIViewController) -> UIViewController? {
        let primaryTab = splitViewController.viewControllers.first as! UITabBarController
        let primaryNavi = primaryTab.selectedViewController as! UINavigationController
        
        if primaryNavi.viewControllers.count > 1 {
            return primaryNavi.popViewControllerAnimated(false)
        } else {
            return nil
        }
    }
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?