0

我正在尝试做与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 控制器没有显示。甚至没有导航控制器栏。有什么我做错了吗?

谢谢

4

1 回答 1

0

我忘记输入view.addSubView(viewController?.view)didSet。解决了。

于 2014-06-28T17:47:03.033 回答