UIApplicationDelegate in Builder Interface with Xcode 4.2

My application is a presentation based application. I need to create a UINavigationController as my rootViewController .

In a previous version of Xcode, there was an xib file called mainWindow , in which we could:

  • Connect our implementation of UIApplicationDelegate to the output of the UIApplication delegate
  • Connect UIWindow to UIApplicationDelegate
  • Connect the UIViewController to the UIWindow property rootViewController .

But now (Xcode 4.2) does not create this xib file!

So, how can I create a custom UINavigationController and connect it to my implementation of UIApplicationDelegate in InterfaceBuilder?

Here is my code in my implementation of UIApplicationDelegate :

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { SDWebImageRootViewController *root = [[SDWebImageRootViewController alloc] initWithNibName:nil bundle:nil]; _navigationController = [[[UINavigationController alloc] initWithRootViewController:root] autorelease]; self.window.rootViewController = _navigationController; [[_navigationController navigationBar] setBarStyle:UIBarStyleBlack]; [[_navigationController navigationBar] setTranslucent:YES]; [_window addSubview:[_navigationController view]]; } 
+4
source share
1 answer

First of all, yes, you can still use IB for this even in the latest version of Xcode, so I'm not sure where you got it from.

If you want to know how to specify an application delegate without IB, this is pretty simple:

In your main method, just use the application delegate class name as the 4th parameter for UIApplicationMain :

 int main(int argc, char *argv[]) { @autoreleasepool { int retVal = UIApplicationMain(argc, argv, nil, @"APPLICATION_DELEGATE_CLASS_NAME"); return retVal; } } 

In fact, Xcode 4.2 does this for you by default when creating an application based on a view from a template (although it does not use a static string ... which is probably better than my suggestion, honestly, because it would get refactored if you use built-in refactoring, etc.):

NSStringFromClass([AppDelegate class])

To answer the following question: ok , then what should I do ? to connect the UINC outlet in interface ? ok , then what should I do ? to connect the UINC outlet in interface ?

Do not worry.

Still not believing me? Great ... here's the tutorial ... it's FIFTEEN steps! ... and completely pointless.

First create an application:

enter image description here

Open main.m and replace the fourth parameter with nil :

enter image description here

Create a new xib or grab the existing one (which I am going to do here) and create the File Owner UIApplication .

enter image description here

Then add Object from the toolbar and change the class to your subclass of UIApplicationDelegate :

enter image description here

Now go back to the file owner and connect the delegate output to the added UIApplicationDelegate . Remove the view link if you do what I did and capture the existing xib.

enter image description here

Now add UIWindow from the toolbar.

enter image description here

Now add the 'UIViewController from the toolbox. This is your custom from the toolbox. This is your custom UIViewController . If you want a . If you want a UINavigationController or UITableViewController` just add this instead.

enter image description here

If you are using a custom UIViewController class, specify the class here:

enter image description here

Connect the UIWindow rootViewController to your UIViewController :

enter image description here

UIApplicationDelegate your UIApplicationDelegate interface and create or modify the window property to make it an IBOutlet .

enter image description here

Switch to the implementation and remove any "useless" code that configures your window controller and root view. (I'm sarcastically here ... this short code does everything we do here ... just programmatically, not through IB.)

enter image description here

Go back to your xib and connect the UIApplicationDelegate window output to it.

<T411>

Now, in your target deployment information, set xib as the β€œMain Interface”:

enter image description here

Done ... pshew!

+8
source

Source: https://habr.com/ru/post/1389947/


All Articles