It is not knowledge, but the act of learning, not possession but the act of getting there, which grants the greatest enjoyment.
Johann Carl Friedrich Gauss (1808), Letter to Bolyai
Back to post archive
Xcode 4.2: Where has the MainWindow.xib gone? Creating an empty application - 12 Simple Steps

I remember coming across this problem when I was brand new to Xcode 4.2. Prior to this version, you would create an empty application and a MainWindow.xib file was readily prepared for you. In the new versions of Xcode this is no longer the case. There are some good tutorials around on the web that show give a very comprehensive solution to this problem from scratch. But if you want to skip all that and just get your MainWindow back then there are 12 simple steps you can follow which are significantly more simple than others and produce the same result. However if you want to learn more about the internal structure of your application, the connections, app delegates etc. I recommend you follow the other tutorials.

Below are step-by-step instructions with screen captures; if you don't think you'll need them, you can skip to here for the summarised steps.

Missing your MainWindow.xib? Let's get her back:

1. Open Xcode 4.2+

2. Go to File > New > New Project

3. Under 'iOS' select 'Application'. Then you want to select 'Empty Application' and press next.



4. Give your project/app a name. I've named mine after the Ancient Egyptian Pharaoh of the 21st Dynasty, Psusennes I. Enter this name into the 'Class Prefix' as well (if you wish). Press next.

5. Go to File > New > New File

6. Select 'User Interface' under 'iOS' and choose 'Application'. Press next.



7. You'll be prompted to create a .xib file. Name it "MainWindow" (without the .xib extension) and press Create. Your navigator on the left should look something like this:



8. In the interface builder, under 'Objects' select 'App Delegate'. Then, in the Utilities panel choose the Identity Inspector (The third icon from the left). Under 'Custom Class' type in the name of your App Delegate class in the input box. In my case I would enter 'PsusennesAppDelegate'. Under 'Identity', select the Label where it is written 'App Delegate', remove its content and press enter.



You should see that after pressing Enter the App Delegate Object in the left pane will change to '<Your app name> App Delegate'.

9. In the Navigator select your project. In the summary tab, select your project under 'Targets'. Click the 'Main Interface' drop-down menu and enter/select 'MainWindow' and press enter.



10. Now in the Navigator, select your App Delegate interface file (.h). We need to declare the window in the interface file as an outlet so that we can link it in the Interface Builder. Make the changes highlighted below:



11. Select 'MainWindow.xib' in the Navigator. In the interface builder, whilst pressing Ctrl + Click the App Delegate object and drag it the Window object. Then select 'window' in the popup.



12. We'll just test it to make sure everything has worked. Change the background colour of the window to any that you like. Press Run and the iPhone Simulator should launch and the app should open and display your newly painted window.

Steps Summarised

1. Open Xcode 4.2 (no seriously!)
2. Go to File > New > New Project
3. Under 'iOS' select 'Application'. Then you want to select 'Empty Application' and press next.
4. Give your project/app a name. Press next.
5. Go to File > New > New File
6. Select 'User Interface' under 'iOS' and choose 'Application'. Press next.
7. You'll be prompted to create a .xib file. Name it "MainWindow" (without the .xib extension) and press Create.
8. In the interface builder, under 'Objects' select 'App Delegate'. Then, in the Utilities panel choose the Identity Inspector (The third icon from the left). Under 'Custom Class' type in the name of your App Delegate class in the input box. Under 'Identity', select the Label where it is written 'App Delegate', remove its content and press enter.
9. In the Navigator select your project. In the summary tab, select your project under 'Targets'. Click the 'Main Interface' drop-down menu and enter/select 'MainWindow' and press enter.
10. Now in the Navigator, select your App Delegate interface file (.h). We need to declare the window in the interface file as an outlet so that we can link it in the Interface Builder. (You may need to scroll up for the screen capture for this one!)
11. Select 'MainWindow.xib' in the Navigator. In the interface builder, whilst pressing Ctrl + Click the App Delegate object and drag it the Window object. Then select 'window' in the popup.
12. Test it to make sure everything has worked. Change the background colour of the window to any that you like. Press Run and the iPhone Simulator should launch and the app should open and display your newly stained window.


Hope that helps anyone looking for a quick and simple solution.


Your Comments
There are currently no comments for this post


Post your comment  
Name:

Email address (Optional):

Your Comment:

B I U Insert link


5000 characters left

Preview your comment


Press the 'Preview' button to preview your comment
Terms of use • Website Designed & Programmed by Shad Deen • Copyright © 2011-12, All Rights Reserved.