10

What steps do I need to do? In Objective-C we created a rootViewController and detailViewController, after there added this controllers to splitViewController. For example:

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.backgroundColor = [UIColor whiteColor];
    UISplitViewController *splitViewController = [[UISplitViewController alloc] init];
    MTTRootViewController *rootViewController = [[MTTRootViewController alloc] init];
    MTTDetailedViewController *detailedViewController = [[MTTDetailedViewController alloc]init];
    splitViewController.viewControllers = [NSArray arrayWithObjects:rootViewController, detailedViewController, nil];
    [self.window setRootViewController:(UIViewController*)splitViewController];
    [self.window makeKeyAndVisible];
    return YES;
}

How can I do the same in Swift?

2 Answers 2

19

if you want do it with navigationController, then try it:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
    self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
    self.window!.backgroundColor = UIColor.whiteColor()
    var splitViewController =  UISplitViewController()
    var rootViewController = RootViewController()
    var detailViewController = DetailViewController()
    var rootNavigationController = UINavigationController(rootViewController:rootViewController)
    var detailNavigationController = UINavigationController(rootViewController:detailViewController)
    splitViewController.viewControllers = [rootNavigationController,detailNavigationController]
    self.window!.rootViewController = splitViewController
    self.window!.makeKeyAndVisible()
    return true
}
Sign up to request clarification or add additional context in comments.

Comments

4

After some time I found answer:

At first time need create rootViewController and detailViewController. For example, rootViewController will be inherit from UITableViewController and detailViewController will inherit from UIViewController. At next time you will need do this:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
        self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
        self.window!.backgroundColor = UIColor.whiteColor()
        var splitViewController =  UISplitViewController()
        var rootViewController = RootViewController()
        var detailViewController = DetailViewController()
        splitViewController.viewControllers = [rootViewController,detailViewController]
        self.window!.rootViewController = splitViewController
        self.window!.makeKeyAndVisible()
        return true
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.