SplitView控制器未显示

时间:2014-06-28 14:56:42

标签: ios swift ios8 wwdc

我尝试做与adaptivephotos WWDC 2014示例应用程序相同的操作,因此我的AppDelegate.swift包含以下代码:

class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDelegate {

var window: UIWindow!


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
    // Override point for customization after application launch.
    window = UIWindow(frame: UIScreen.mainScreen().bounds)
    var splitViewController = UISplitViewController()
    var searchBoxViewController = SearchBoxViewController()
    var searchResultDetailViewController = SearchResultDetailViewController()
    var navigationController = UINavigationController(rootViewController: searchBoxViewController)
    splitViewController.viewControllers = [navigationController, searchResultDetailViewController]
    splitViewController.delegate = self
    NSLog("%@", splitViewController.viewControllers)
    var mainViewController = MainViewController()
    mainViewController.view.backgroundColor = UIColor.redColor()
    mainViewController.viewController = splitViewController
    window.backgroundColor = UIColor.whiteColor()
    window.rootViewController = mainViewController
    window.makeKeyAndVisible()
    return true
}

func applicationWillResignActive(application: UIApplication) {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

func applicationDidEnterBackground(application: UIApplication) {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(application: UIApplication) {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(application: UIApplication) {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(application: UIApplication) {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

}

我有这样的MainViewController.swift:

class MainViewController: UIViewController {

var viewController : UIViewController {
    didSet {
        addChildViewController(viewController)
    }
}

init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
    viewController = UIViewController()
    super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
    // Custom initialization
}

init(coder aDecoder: NSCoder!)
{
    viewController = UIViewController()
    super.init(coder: aDecoder)
}

override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}


/*
// #pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue?, sender: AnyObject?) {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

}

但是splitview控制器并没有显示出来。甚至不是导航控制器栏。我有什么不对的吗?

谢谢

1 个答案:

答案 0 :(得分:0)

我忘记在view.addSubView(viewController?.view)中加入didSet。解决。

相关问题