Start screen in storyboard

Asked

Viewed 366 times

2

I’m using Xcode for app development.

In it I use the storyboard for the canvases. Suppose the structure of canvases is as follows:

I have 5 sequential screens, which one leads to the next, until arriving at the fifth (last) screen. My home screen, set via storyboard is the number 1 screen. For navigation, I have a UINavigationController.

I would like to know how I can start the app on another screen, so that I do not miss the navigation among the others. For better example: Start on screen 4, but be able to return to screen 3 or follow to screen 5.

Note: The code can be in Swift or Objective-C.

  • You can put the code you’re using in your main?

  • Actually in Appdelegate is the default code, created by Xcode. I did not make any changes

  • I programmed a few years ago with Xcode... there is no initializer that you speak to View that will open?

  • @Paulohdsousa When creating and defining the initial Uiviewcontroller via storyboard, it does all this implicitly. There is as I leave without initial controller, and set it in the way when to boot the app, but so I lose the navigation reference to screen 3, due it is not allocated in memory.

  • @Gian http://www.raywenderlich.com/113388/storyboards-tutorial-in-ios-9-part-1 These examples can give you a light

2 answers

1

What you can do is create the Views stack programmatically by Appdelegate.

I never tried to create the whole stack dynamically, I just changed the already existing. I can’t test at the moment, so I can’t guarantee that work, but it’s a way.

Follows implementation:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    self.window = UIWindow(frame: UIScreen.mainScreen().bounds)

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

    let tela_1 = storyboard.instantiateViewControllerWithIdentifier("tela_1") as! UIViewController
    let tela_1 = storyboard.instantiateViewControllerWithIdentifier("tela_2") as! UIViewController
    let tela_3 = storyboard.instantiateViewControllerWithIdentifier("tela_3") as! UIViewController
    let tela_4 = storyboard.instantiateViewControllerWithIdentifier("tela_4") as! UIViewController
    let tela_5 = storyboard.instantiateViewControllerWithIdentifier("tela_5") as! UIViewController

    let navigationController = storyboard.instantiateInitialViewController() as UINavigationController
    navigationController.viewControllers = [tela_1, tela_2, tela_3, tela_4, tela_5]

    self.window?.rootViewController = tela_4
    self.window?.makeKeyAndVisible()

    return true
}

Note: Don’t forget to exchange "tela_N" for the name of your actual classes.

  • Your answer will not have the desired effect since you define as rootViewController tela_4 and not the navigationController. And in case it is only a digitization error the array of viewControllers should be [tela_1, tela_2, tela_3, tela4] so tela_4 is the one that will be at the top of the stack.

-1

I don’t know what the context of your app is, but this type of navigation doesn’t seem to be very usable. Take a look at Human Interface Guide for iOS on the topic of UI Elements - Tab Bar:

https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/MobileHIG/Art/music_tab_bar_iphone_2x.png

A tab bar gives people the Ability to switch between Different subtasks, views, or modes in an app.

Then using Tab Bar you can have this control of your 5 screens so that the navigation between them becomes more intuitive.

In case how to start from a specific screen (screen 4 for example) take a look at this stackoverflow question here

Browser other questions tagged

You are not signed in. Login or sign up in order to post.