我如何更改 xcode 中的默认 ViewController

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5249507/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 20:25:18  来源:igfitidea点击:

how do i change the default ViewController in xcode

iphoneobjective-cxcodeipaduiviewcontroller

提问by jebberwocky

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. how could i do this?

现在我想添加一个名为“notdummyViewController”的视图并让它在开始时加载以替换 dummyViewController。我怎么能这样做?

回答by Don

In your _info.plist, you'll have a "Main nib file base name", most likely MainWindow. Open up this xib and change the class of the View Controller to notdummyViewController.

在您的 _info.plist 中,您将有一个“Main nib 文件基名”,很可能是 MainWindow。打开这个xib,把View Controller的类改成notdummyViewController。

回答by SPatil

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!

现在您已准备好启动应用程序!

回答by jebberwocky

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;
}