Use the empty application template in xcode4.2 to replace the old window based application

Source: Internet
Author: User

 "FYI, I am very newbie in iPhone development ."

I had upgraded xcode to 4.2 beta 4 and realized that there is no more templates for iOS 4.
Obviusly, it did not include IOS 4 SDK because it said "With iOS 5 SDK", duh!
I cocould not go back to xcode beta 3 since I upgraded my iPhone to beta 4 as well.

Anyway...

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

 

Bytes ------------------------------------------------------------------------------------------------------------------

Mainwindow. xibposted on

2011-06-16
Jeroen trappers

In the xcode 4.2 beta, mainwindow. XIB is no longer stored ded 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
Xappdelegate. 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. Choose
IOS> User Interface> emptyAs template. Next,
Choose iPhone, next give it the nameMainwindow(. 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 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 hook it up in interface builder. The xappdelegate. h shoshould read something like this:

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

Don't forgetSaveThe file, otherwise interface builder will not be able to pick up the outlet. Next we continue editing the mainwindow. XIB

  • Control-drag fromDelegateOutlet of the file owner to the xappdelegate object.

  • Control-drag fromWindowOutlet 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 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 shocould 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.

 

 

I hope this helps to understand exactly how an iOS app starts. the next thing you shoshould 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.

Kthxbye

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.