xcode4.2手动添加MainWindow.xib

参考来自:http://blog.csdn.net/muyu114/article/details/6896498

1、新建一个空的应用程序

Start with Empty Application template

2、添加一个空的xib文件

 Add Empty Interface Builder document

到这里工程的应该是下面这个样子的:

The empty design surface of MainWindow.xib

3、改变File’s Owner的class为UIApplication

Change class of File's Owner to UIApplication

4、从Library中添加一个Object,并设置其class为你对应的应用程序的类(这里是DemoAppDelegate)

Add Object to the document

Change class of the object to xAppDelegate

5、添加windows,并在程序中设置windows为IBOutlet

Add a window to the document

The xAppDelegate.h should read something like this:

@interface DemoAppDelegate : UIResponder <UIApplicationDelegate> @property (strong, nonatomic) IBOutlet UIWindow *window; @end

6、将windows与xib中的文件连接起来,并设置相应的代理

Link the application delegate

  • Control-Drag from the window outlet of the xAppDelegate to the Window.

Link the window outlet of the app delegate

  • Just for this demo, I’m adding a label to the window.

Add a label for testing

7、设置应用程序的主界面

  • Navigate to the project, and in the Summary tab, select MainWindow as the Main Interface.

Set the Main Interface to MainWindow

You can now run the project in the Simulator, and the window should show up. However there’s one last thing you might want to clean up. In xAppDelegate.m, there was actually code that creates a window as well. Just put the method

- (BOOL) application:didFinishLaunchingWithOptions:

in comment.

we're done

I hope this helps to understand exactly how an iOS app starts. The next thing you should do is add a ViewController, and push it onto the MainWindow. I’m not going to cover that here. Please leave your feedback in the comments.

原文地址:https://www.cnblogs.com/foxmin/p/2434437.html