简体   繁体   中英

Why detailViewController is not in UISplitViewController.viewControllers anymore?

I use UISplitViewController to build my app. Both the master view controller and detail view controller are UINavigationControllers, as illustrated in the Figure. 故事板

In the viewDidLoad() functions of both master vc and detail vc, the following code is inserted:

    println(self.splitViewController!.viewControllers.count)
    for vc in self.splitViewController!.viewControllers {
        println(vc.hashValue)
    }

The result is:

master vc.viewDidLoad()

2
140692681984032
140692680836304

detaiVC.viewDidLoad()

1
140692681984032

It turns out that in detaiVC.viewDidLoad(), detailVC is not in splitViewController.viewControllers any more. Why?

When running your app in a compact width, the splitviewcontroller will be compacted. ie the var viewControllers property only contains 1 view controller.

From the documentation:

When the split view interface is expanded, this property contains two view controllers; when it is collapsed, this property contains only one view controller.

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UISplitViewController_class/#//apple_ref/occ/instp/UISplitViewController/viewControllers

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM