Hello, as you have noticed there is no MainWindow in the empty templates of Xcode 4.2 as in the previous versions of Xcode. Thus, we can go through this new approach or try to do it as was before.
Please note that these instructions are just to remind me how to do it. I will elaborate the instructions in a better way other day; when I have more time to do it. Meanwhile, you can visit the site of Jeroen Trappers. In this post he explains in detail how to recreate the MainWindow.
Needless to say, here you have the principal instructions in order to have your own MainWindow:
- Create a new project
- Add a new empty interface file, to be simplistic use the name MainWindow, but you can use the name you want.
- Click on the new created file. This take to the new Interface Builder.
- Change the class of File’s Owner to UIApplication.
- From the objects library drag the general Object onto the Objects section in the left side of the Xcode Interface Builder.
- Change the class of such Object to AppDelegate.
- From the objects library drag the Window object onto the Objects section.
- To hook everything up; first we add the code below in the AppDelegate interface file (AppDelegate.h)
@property (strong, nonatomic) IBOutlet UIWindow *window;
Then we click on the MainWindow.xib and after that on the File’s Owner. From the bindings sections of the File’s Owner (fifth tab on the right side) we perform a control-drag from the outlet delegate to the AppDelegate Object in the Objects section
- Now click on the AppDelegate object in the objects sections. From the bindings section (fifth tab at the right side) we perform a control-drag from the outlet window to the window object in the objects section.
- After hook everything we have to indicate what our main interface is. To do that, we navigate to the project and in the summary tab we select MainWindow as our Main Interface.
- To finalize we have to comment the piece of code that creates the window in the AppDelegate.m. The method that we have to comment is:
– (BOOL) application:didFinishLaunchingWithOptions:
- That’s it. Now you can run your app and the window.xib will be launched. You can add a button or label just to be sure that the launched window is the one that we have created.
Thank you for reading this. Tot Straks!