在使用之前,SplitViewController应该在索引0处有一个视图控制器?

时间:2016-08-09 21:52:28

标签: ios swift uisplitviewcontroller

每次显示分割视图控制器时,我都会在控制台中出现此错误。我无法找到具体的解决方案吗?指导?

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

    window = UIWindow(frame: UIScreen.mainScreen().bounds)
    window?.makeKeyAndVisible()
    let splitViewController = UISplitViewController()
    let masterViewController = TabBarMaster(collectionViewLayout: UICollectionViewFlowLayout())
    let detailViewController = UINavigationController()

    splitViewController.maximumPrimaryColumnWidth = 80

    splitViewController.preferredDisplayMode = .AllVisible
    splitViewController.delegate = self
    splitViewController.viewControllers = [masterViewController, detailViewController]
    window?.rootViewController = splitViewController

    return true
}

1 个答案:

答案 0 :(得分:9)

在设置splitViewController的任何其他属性之前设置splitViewController viewControllers数组:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

    window = UIWindow(frame: UIScreen.mainScreen().bounds)
    window?.makeKeyAndVisible()
    let splitViewController = UISplitViewController()
    let masterViewController = TabBarMaster(collectionViewLayout: UICollectionViewFlowLayout())
    let detailViewController = UINavigationController()

    splitViewController.viewControllers = [masterViewController, detailViewController] // move it here

    splitViewController.maximumPrimaryColumnWidth = 80
    splitViewController.preferredDisplayMode = .AllVisible
    splitViewController.delegate = self
    window?.rootViewController = splitViewController

    return true
}