简体   繁体   English

我如何更改 xcode 中的默认 ViewController

[英]how do i change the default ViewController in xcode

if i have a View-based project like this如果我有这样一个基于视图的项目

dummyAppDelegate.h
dummyAppDelegate.m
dummyViewController.h
dummyViewController.m
dummyViewController.xib

now i want to add a view called "notdummyViewController" and make it load at start to replace dummyViewController.现在我想添加一个名为“notdummyViewController”的视图,并在开始时加载它以替换 dummyViewController。 how could i do this?我怎么能这样做?

In your _info.plist, you'll have a "Main nib file base name", most likely MainWindow.在您的 _info.plist 中,您将有一个“Main nib 文件基名”,很可能是 MainWindow。 Open up this xib and change the class of the View Controller to notdummyViewController.打开这个xib,把View Controller的类改成notdummyViewController。

You have this code in your appDelegate applicationnDidFinishLaunching您的 appDelegate applicationnDidFinishLaunching 中有此代码

[window addSubview:viewController];
[window makeKeyAndVisible];

In ur dummyAppDelegate.h the viewCOOntroller is of type dummyViewController So now what you can do is change the viewController object in .h to notDummyViewController type在你的 dummyAppDelegate.h 中,viewCOOntroller 的类型是 dummyViewController 所以现在你可以做的是将 .h 中的 viewController 对象更改为 notDummyViewController 类型

And one more step remaining is in MainWindow.xib change the viewcontroller type to notdummyViewController and assign it to File Owners viewController property!剩下的一步是在 MainWindow.xib 中将 viewcontroller 类型更改为 notdummyViewController 并将其分配给 File Owners viewController 属性!

And now you are ready to launch the application!现在您已准备好启动应用程序!

i figured out but not sure it is the appropriate approach我想通了但不确定这是合适的方法

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    // Override point for customization after app launch. 
    notdummy = [[notdummyViewController alloc]init];
    [self.window addSubview:notdummy.view];
    [self.window makeKeyAndVisible];

    return YES;
}

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

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