现在的位置: 首页 > 综合 > 正文

iPhone开发入门1 - 创建一个window-Based程序

2013年10月15日 ⁄ 综合 ⁄ 共 3434字 ⁄ 字号 评论关闭

iPhone Programming - Basic Hello world Application

In this tutorial I will walk to you through creating a basic “Hello World” application using a basic template files generated by xcode for the iPhone. There are many ways that a Hello World program could be made on the iPhone, I am going to show you the simplest. This tutorial assumes you have a basic understanding of Objective-C. Apple has provided a very simple and straight forward tutorial on Objective-C. You can find it here.

You will learn how to:

This tutorial assumes that you have already installed the iPhone SDK. If you are unsure how to do this, click and follow the steps.

Creating a Window-Based Application

Open Up Xcode

You will be doing all of your development in Xcode. Then close the Welcome window (if it shows up)

Start a new iPhone OS Project
Click Xcode > New Project and a window should pop up like this:

Make sure Application is selected under iPhone OS and then select Window-Based Application. Click Choose… It will ask you to name your project. Type in “HelloWorld_Default_iappdevs” and let’s get started.

Learn About the Default Files

What is all this stuff?
There are quite a few files that get added to your project. At first glance, this looks kind of intimidating. Don’t worry, we only need to edit one of them. Here is a quick explanation of the different files. You don’t have to read this part but having this many files is what confused me the most when I started developing for the iPhone.

  1. CoreGraphics.framework, Foundation.framwork, UIKit.framework - You guessed it, this is a set of library functions provided by Apple that we use in our application. We use these as includes similar to any other language that includes library functions.
  2. HelloWorld_Default_iappdevs.app - This is your app that gets installed on the iPhone. We don’t really need to worry about this right now
  3. HelloWorld_Default_iappdevs_Prefix.pch - This is another include file that gets compiled separately from your other files so you don’t need to include it on each file. It contains some code to include the data inside the frameworks.
  4. HelloWorld_Default_iappdevs AppDelegate.h - This is a header file that contains all of our definitions for variables that we will be using. It’s very similar to a header file in C or C++;
  5. HelloWorld_Default_iappdevs AppDelegate.m - All of the magic starts here. Consider this file our starting point for execution. The main.m file invokes this object.
  6. Info.plist - This contains various meta information about your program. You won’t really need to edit this until you are ready to start testing on the iPhone
  7. main.m - Like most programming language, this file contains our main function. This is where execution begins. The main function basically instantiates our object and starts the program. You shouldn’t need to edit this file.
  8. MainWindow.xib - This contains the visual information of our main window. If you double click on it, it will open in a program called “Interface Builder”. We will get to this a little later. Just on thing to note is this file does not contain any code.

Now, all of these files together create a basic program. Go ahead and click on the Build and Go button at the top of Xcode. Make sure the drop-down on the top left says Simulator | Debug, this tells Xcode that we are testing on the iPhone simulator.

 

You will see the iPhone simulator start and your program will launch. It’s not very interesting at the moment.

Now just open MainWindow.xib as shown below (Double click on that )

Then it will be opened in interface builder.

In interface builder you may find four different windows.

1) MainWindow.xib

2) Window

3) Inspector window

4) Library window.

If You not find these don’t worry.

Just click on Tools in interface builder menu bar

Tools—->library

Tools—->inspector

In this way you can open them

Select the library window and drag and drop the label on window, then double click on dropped label and change the text as “Basic Hello World”. As shown below

And save it then build and go

Final Out put

抱歉!评论已关闭.