简体   繁体   中英

iOS start app at a “detail view” instead of RootVIewController created by Navigation Controller

Basically, I dropped a Navigation Controller, added 3 rows to the RootView's TableView, set a segue from the first row to a ViewController (The "detail view"). Now I want to start my app at this "detail view". I tried to set the initial view as the "detail view", but it didn't worked. Latter I tried to trigger the segue, but I could not get it to work, and that solution seemed hacky, I decided to ask you people what would be the correct approach.

Thanks in advance for any reply!

You can use splitviewController to do the trick, if your app only runs on iPhone.

Drop in a splitviewcontroller and set it as the initial view controller.

Make the tableviewcontroller embedded in a Navigation Controller,and set the Navigation Controller to be the master view controller of the splitviewController.

Make the detailviewcontroller embeded in a Navigation Controller,and set the navigation conntroller to be the detail view controller of the splitviewController.

Then create the segue ,your storyboard should looks like this:

故事板

For more details you can download the demo of Stanford cs 193p Lecture 8: Psychologist VCL.zip

You can set initial view Controller from appDelegate class.

And here is your code:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Override point for customization after application launch.

    // mainStoryboard
    let mainStoryboard = UIStoryboard(name: "Main", bundle: nil)

    // rootViewController
    let rootViewController = mainStoryboard.instantiateViewControllerWithIdentifier("DetailViewController") as? UIViewController

    // navigationController
    let navigationController = UINavigationController(rootViewController: rootViewController!)

    navigationController.navigationBarHidden = true // or not, your choice.

    // self.window
    self.window = UIWindow(frame: UIScreen.mainScreen().bounds)

    self.window!.rootViewController = navigationController

    self.window!.makeKeyAndVisible()

    return true
}

And don't forget to assign StoryBoard ID from Identity Inspector and it will look like:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM