2014-06-28 47 views
0

我試圖做同樣的事情在adaptivephotos WWDC 2014的示例應用程序,所以我有我用下面的代碼AppDelegate.swift:SPLITVIEW控制器沒有顯示

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控制器不顯示。甚至沒有導航控制器欄。有什麼我做錯了嗎?

謝謝

回答

0

我忘了在view.addSubView(viewController?.view)didSet。解決了。