XCode4.2中使用Empty Application模板替代旧的Window Based Application

转载 2011年10月13日 16:33:04
 “FYI, I am very newbie in iPhone development.”

I had upgraded Xcode to 4.2 beta 4 and realised that there is no more templates for iOS 4.
Obviously, it did not include iOS 4 SDK because it said “with iOS 5 SDK”, duh!
I could not go back to Xcode beta 3 since I upgraded my iPhone to beta 4 as well.


In the tutorial that I am learning at the moment, it requires “Window-based application”.
Xcode 4.2 beta 4 does not have “window-based application”; so, I created a project with “Empty application”.
Unfortunately, “Empty application” has no longer “MainWindow.xib”, which tutorial teacher said to modify something in it.
So, I googled to make “MainWindow.xib” visible and found this article.

“MainWindow.xib” posted by Jeroen Trappers




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.

Start with Empty Application template

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 an xAppDelegate.h and .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. Choose iOS > User Interface > Empty as template. Add Empty Interface Builder documentNext, choose iPhone, next give it the name MainWindow (.xib will be added automatically). By the way, the name of the file is not very important, but it’s nice to choose MainWindow, because that’s familiar.

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.

The empty design surface of MainWindow.xib

  • Change the class of File’s Owner to UIApplication

Change class of File's Owner to UIApplication

  • Find Object in the Library and drag it onto the Objects pane on the left.

Add Object to the document

  • 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.

Change class of the object to xAppDelegate

  • Add a Window to the Objects pane on the left.

Add a window to the document

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  hook it up in Interface Builder. The xAppDelegate.h should read something like this:

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

Don’t forget to save the file, otherwise Interface Builder will not be able to pick up the Outlet. Next we continue editing the MainWindow.xib

  • Control-Drag from the delegate outlet of the File Owner to the xAppDelegate object.

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

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.

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.


从Empty Application到Window Based Application

1.创建Empty application,此时项目中只有一个AppDelegate的类 2.新建文件,选择User Interface下的Empty 命名为MainWindow 3.打开...
  • yipanbo
  • yipanbo
  • 2014年06月19日 15:29
  • 546

Xcode7.2中如何添加一个Empty Application模板

大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处. 如果觉得写的不好请多提意见,如果觉得不错请多多支持点赞.谢谢! hopy ;) Xcode 6.0正式版之后已经没有所谓的Empty A...
  • mydo
  • mydo
  • 2016年02月15日 15:29
  • 3441

Xcode7之空工程(Empty Application)

众所周知,从Xcode 6正式版开始就没有了空工程( Empty Application) 这个模板。 那么如果我们因为工程需要,想继续创建空工程怎么办呐?接下来小编就来告诉你:...
  • MinJing_Lin
  • MinJing_Lin
  • 2015年12月23日 14:47
  • 1241

Codeblocks中的empty project和console application

empty project:只有空工程,需要自己添加源文件 console application:貌似给写好了主函数...
  • u014791046
  • u014791046
  • 2016年06月05日 02:00
  • 617

芒果iOS开发之Xcode安装Empty Application

相信用过Xcode6.0之前版本的开发人员都会有一个疑惑,苹果从Xcod的6.0之后就取消了Empty Applicate也就是空工程的创建。也就是下边这个图标: 空工程没有之后取而代之的是S...
  • CrazyZhang1990
  • CrazyZhang1990
  • 2015年11月17日 17:50
  • 950

XCode4.2中没有Window Base Application解决办法

发现XCode4.2中没有Window Base Application这一选项.使用Empty Application没有主界面的Storyboard文件. 于是打开google,发现Jeroen...
  • niitlcj
  • niitlcj
  • 2012年02月22日 10:50
  • 1660

xcode4.3 中Storyborad 替代了window based application

这篇文章是学习StoryBoard的 http://blog.sina.com.cn/s/blog_5a6efa3301015f9f.html
  • CharlotteWeb
  • CharlotteWeb
  • 2012年07月05日 00:41
  • 217

Xcode建立Window based Application

XCode 4 以后,项目模版中没有了 Window-based Application,跟它比较接近的项目模版是 Empty Application. 如下图的选择: 我们想建一个 W...
  • king2716
  • king2716
  • 2013年04月30日 22:47
  • 433

net4.0创建asp.net empty web application如何发布(英文)

net4.0创建asp.net empty web application 项目右键弹出窗口 选择 “public”
  • king_hh
  • king_hh
  • 2017年02月28日 10:14
  • 399

Xcode4.2中 添加 Window-Based Application 模板

添加 Window-Based Application 模板 在最新的 iOS SDK 中,Apple 去掉了该模板,并且会默认选 择 Storyboard 和 Automatic Ref...
  • guchengluoye
  • guchengluoye
  • 2012年05月24日 17:08
  • 846
您举报文章:XCode4.2中使用Empty Application模板替代旧的Window Based Application