简体   繁体   English

Swift iOS7故事板-自行启动主场景

[英]Swift ios7 storyboard - launch main scene myself

I want to control which scenes are visible myself from A to Z if possible. 如果可能的话,我想控制哪些场景可以从A到Z看到。

I am new to iOS, but decided to go with using storyboard because it seems to be the direction things are heading. 我是iOS的新手,但是决定使用Storyboard,因为这似乎是事情发展的方向。

From my own perspective, I am going to view it as a tool to design multiple scenes in one place, but I wan to control transiions in my own code. 从我自己的角度来看,我将其视为在一个地方设计多个场景的工具,但我希望在自己的代码中控制过渡。 (I am porting from another language and tool that already manages and tracks logic flow itself) (我从已经可以自行管理和跟踪逻辑流的另一种语言和工具进行移植)

That leads me to my question - I would prefer to load/choose my first/primary scene myself upon startup and "launch" it myself. 这引出了我的问题-我宁愿在启动时自行加载/选择第一个/主要场景,然后自己“启动”它。 How do I best do so? 我最好怎么做?

If you want to make any view controller to show at first then just click your view controller in storyboardand click on is initial view controller 如果要首先显示任何视图控制器,则只需在情节提要中单击视图控制器,然后单击“是初始视图控制器”即可。

From Code (In AppDelegate) 从代码(在AppDelegate中)

Swift 迅速

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

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

    var initialViewController = storyboard.instantiateViewControllerWithIdentifier("LoginSignupVC") as! UIViewController

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

    return true
}

Objective C 目标C

   - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];

UIViewController *viewController = // determine the initial view controller here and instantiate   it with [storyboard instantiateViewControllerWithIdentifier:<storyboard id>];

self.window.rootViewController = viewController;
[self.window makeKeyAndVisible];

return YES;
}

Yes you could do that. 是的,你可以那样做。 For each storyboard you have an initial view controller and each view controller in storyboard has an unique identifier. 对于每个情节提要,您都有一个初始视图控制器,并且情节提要中的每个视图控制器都有一个唯一的标识符。 Thus while creating object of view controller in the code you can just specify identifier of the view controller which you want to create. 因此,在代码中创建视图控制器的对象时,您只需指定要创建的视图控制器的标识符即可。

First scene to be visible after splash screen is root view controller, which also you can create programatically and can be loaded from storyboard using identifier for that view controller. 启动画面后第一个可见的场景是根视图控制器,您也可以编程创建该场景,并且可以使用该视图控制器的标识符从情节提要中加载该场景。 You can also load from storyboard without using any identifier, but in that case it would load initial view controller. 您也可以从情节提要中加载而不使用任何标识符,但是在这种情况下,它将加载初始视图控制器。

识别码

You can set identifier for view controller like above in storyboard. 您可以像在故事板上那样为视图控制器设置标识符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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