how do i change the default ViewController in xcod

2020-04-19 06:36发布

问题:

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?

回答1:

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.



回答2:

You have this code in your 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

And one more step remaining is in MainWindow.xib change the viewcontroller type to notdummyViewController and assign it to File Owners viewController property!

And now you are ready to launch the application!



回答3:

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