In the XCode 4.2 beta, MainWindow.xib is no longer included by default in some project templates. This means that you have to get your application to work by writing some code, using another method, or by manually reconstructing MainWindow.xib. This post shows
the latter. Let’s get started.
If you create a new project in XCode 4.2 beta, and choose the Empty Application template to start from, change nothing and try running it in your iPhone 5.0 simulator, you will see an empty – black – screen. The only thing you get from the template is anxAppDelegate.hand.m.
We will now reconstruct our own MainWindow.xib, to get started with development the way you’re used to. So the next thing we do is add a New File to the project.<wbr>Choose<em>iOS > User Interface > Empty</em>as template.<img title="Add Empty Interface Builder document" height="85" alt="Add Empty Interface Builder document" src="http://www.trappers.tk/site/wp-content/uploads/2011/06/Step-2.png" width="325" style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; list-style-type:none; list-style-position:initial">Next,
choose iPhone, next give it the name<em>MainWindow</em>(.xib will be added automatically). By the way, the name of the file is not very important, but it’s nice to choose<em>MainWindow</em>, because that’s familiar.</wbr>
Select the new File we just created. What we have now is an empty design surface, in what used to be Interface Builder. Here we’re going to change some things.
-
Change the class of File’s Owner to UIApplication
-
Find Object in the Library and drag it onto the Objects pane on the left.
-
Change the class of that Object to the xAppDelegate class that was created by the template, you might also want to clear out the “Object” label.
-
Add a Window to the Objects pane on the left.
Now, let’s bind it all together. To do this, we first need to change some of the code in the xAppDelegate.h. We have to add IBOutlet
to the window property it has, so that we can <wbr>hook it up in Interface Builder. The xAppDelegate.h should read something like this:</wbr>
@interface DemoAppDelegate : UIResponder <UIApplicationDelegate> @property (strong, nonatomic)IBOutletUIWindow *window; @end
Don’t forget tosavethe file, otherwise Interface Builder will not be able to pick up the Outlet. Next we continue editing the MainWindow.xib
-
Control-Drag from thedelegateoutlet of the File Owner to the xAppDelegate object.
-
Control-Drag from thewindowoutlet of the xAppDelegate to the Window.
-
Just for this demo, I’m adding a label to the window.
We’re not done yet, but we’re almost there.
-
Navigate to the project, and in the Summary tab, select MainWindow as the Main Interface.
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. InxAppDelegate.m, there was actually code that creates a window as well. Just put the method
- (BOOL) application:didFinishLaunchingWithOp<wbr>tions:</wbr>
in comment.
<wbr></wbr>
<wbr></wbr>
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.
转自:http://blog.sina.com.cn/s/blog_4f1d20f30100twtd.html
相关推荐
由于Empty Application模板不包含任何预设的用户界面文件,因此我们需要手动添加`MainWindow.xib`文件。 1. **添加MainWindow.xib文件**: - 使用快捷键`Cmd + N`打开新建文件对话框。 - 选择“iOS” -> “User ...
iPhone开发基础教程 相配套源码。 第2章 创建基本项目 ... 3.5 编辑MainWindow.xib 3.6 编辑Button_FunViewController.xib 3.6.1 在InterfaceBuilder中创建视图 3.6.2 连接所有元素 3.6.3 测试
7. **添加元素**:在MainWindow.xib中,双击“Window”,然后从Library中拖拽“Label”、“Round Rect Button”和“Text Field”到“Window”中,可以双击这些元素修改它们的名称。 8. **定义视图控制器**:从...
当`MainWindow.xib`被加载时,Xcode的Interface Builder会解析这个文件,创建对应的UI元素。文件中有四个关键组件: 1. **Files Owner**:代表`UIApplication`的实例,它是应用的主要管理者。 2. **FirstResponder*...
通过这个教程,开发者可以了解如何结合Interface Builder和iPhone SDK进行快速的UI开发,以及如何在Xcode中处理xib文件和对象的关联。这不仅简化了代码编写,还使得UI设计更加直观和高效。对于初学者来说,这是一个...
4. **配置Xib文件**:在`MainWindow.xib`中,你需要添加一个`UITabBarController`对象,并将其`delegate`属性连接到`AppDelegate`的实例。同时,通过拖拽`UIViewController`实例到`UITabBarController`下,为每个...
3.5 编辑MainWindow.xib 3.6 编辑Button_FunViewController.xib 3.6.1 在InterfaceBuilder中创建视图 3.6.2 连接所有元素 3.6.3 测试 3.7 小结 第4章 更丰富的用户界面 4.1 满是控件的屏幕 4.2 ...
与.xib文件不同,Storyboard不依赖于MainWindow.xib作为应用的入口点。在使用Storyboard的应用中,AppDelegate不再需要导入UIWindow并声明为IBOutlet,而是直接继承自UIResponder。启动应用时,系统会根据info.plist...
幸运的是,在使用Xcode创建新的项目模板时,你无需手动编写这个函数。Xcode的项目模板已经包含了启动应用所需的所有必要代码。 **`main`函数的实现**: ```objective-c int main(int argc, char *argv[]) { ...
`MainWindow.xib`是应用的主窗口界面文件,使用Interface Builder设计。它定义了应用程序启动时显示的顶级视图控制器和窗口结构。 `NanoLifeiPhoneViewController.xib`是另一个界面文件,可能对应于应用中的一个...
- `MainWindow.xib` - 应用程序的主窗口设计。 - `build/` - 构建过程中产生的中间文件。 - `main.m` - 应用程序的入口点,类似C/C++的`main`函数。 在`main.m`中,`UIApplicationMain`是启动应用的关键函数,它...
5. **MainWindow.xib**:主窗口的用户界面文件,通常包含应用启动时的初始视图控制器。 6. **NanoLifeiPhoneViewController.xib**:可能是一个自定义视图控制器的界面文件,包含了与Core Animation相关的视图和控件...
- `MainWindow.xib`: 主窗口的界面文件,包含应用启动时的初始界面布局。 - `cloudViewController.xib`: 可能是包含贝塞尔曲线动画视图的控制器界面文件。 - `Classes`: 这个目录可能包含了项目的源代码文件,比如...
2. MainWindow.xib:这是Xcode中的用户界面文件,可能用于创建应用程序的主要窗口,包括函数曲线的绘图区域。 3. main.m:这是程序的主入口点,通常包含了程序的初始化代码和事件循环。 4. TestSinCurve.xcodeproj:...
- `MainWindow.xib` 定义了应用的主窗口界面。 - `AlertPickerViewController.xib` 是AlertPicker视图控制器的界面布局文件。 - `AlertPicker.xcodeproj` 是Xcode项目文件,包含了项目设置和依赖关系。 - `Classes` ...
`MainWindow.xib`是主窗口的界面设计文件,它定义了应用启动时的初始视图控制器和界面布局。在这个项目中,可能会包含一个显示浮云动画的视图。 `cloudViewController.xib`是云朵动画控制器的界面设计文件,包含了...
4. **MainWindow.xib**:这是iOS应用的主窗口界面设计文件,通常包含了应用启动时的初始界面。在SQL_Demo中,可能会有一个简单的启动界面或者直接进入主功能界面。 5. **SQL_DemoViewController.xib**:这是一个...