介绍:

许多人对iPhone开发知之甚少,本教程的目标是写一个运行在iPhone模拟器上的“Hello World”程序。如果你不喜欢读这十个步骤,那么你可以直接去观看教程视频

 

编写hello world iPhone程序的10个步骤

 

在你的Hello World程序可以在模拟器上运行前,你需要做好下列准备:

  1. 一台MAC电脑(译者注:实际上pc安装osx也可)
    • MAC电脑必须按照Leopard 10.5.7以上操作系统。
  2. Apple开发者帐号(这是免费注册的)。你还需要安装iPhone SDK。要在iPhone上测试你的代码,你还需要购买开发者许可证,这需要$99,企业需要$299。下面是让你的Hello World程序运行在模拟器上的十个步骤:

 

步骤1: 在下载sdk,升级mac os x到10.5.7或以上后,你就可以安装sdk了。如果你没有升级你的mac到10.5.7或以上版本,你仍然可以按照Xcode,但不能安装iPhone开发包(注意第三张图,iPhone SDK框应该以黑体显示并被选中)

customize UITableView using UITableViewCell
下载的iPhone SDK 2.2.1

customize UITableView using UITableViewCell
安装 iPhone SDK 2.2.1

customize UITableView using UITableViewCell
验证 iPhone SDK安装

(译者注:此教程中sdk为老版本,现在sdk已经到了3.12)

 

步骤 2: 安装后,请打开“Macintosh HD” 然后找到 >Developer>Application>Xcode。运行Xcode

customize UITableView using UITableViewCell
安装iPhone SDK后运行Xcode

 

步骤 3: 在Xcode中建立一个新项目,选择 File>New Project。

customize UITableView using UITableViewCell
建立你的第一个iPhone程序

 

步骤 4: 选择 “View-Based Application”并按 ‘Choose’。取名为HelloWorld,按下‘finish’。

customize UITableView using UITableViewCell
按右下‘chose’

customize UITableView using UITableViewCell
为 iPhone 程序取名

 

步骤 5: 按下 “build and go”,它将启动 iPhone模拟器,你将看到一个灰色的窗口。

customize UITableView using UITableViewCell
文件视图

customize UITableView using UITableViewCell
“Build and GO”按钮
customize UITableView using UITableViewCell
HelloWorld程序输出

 

步骤 6: 按下iPhone模拟器的 home 按钮,你将看到HelloWorld的白色图标。

customize UITableView using UITableViewCell
iPhone 模拟器的Home按钮

customize UITableView using UITableViewCell
Hello world iPhone 程序图标

 

步骤 7: 再次打开 Xcode在Xcode Group and Files中找到 nib文件.。打开 HelloWorldViewController.xib文件。

customize UITableView using UITableViewCell
在Xcode中选择 nib (xib)文件

 

步骤 8:在Interface Build中,选择 View 并按下 cmd + 1 (或按Tools选择 inspector)将背景色改为红色。

customize UITableView using UITableViewCell
在 Interface builder中选择view

customize UITableView using UITableViewCell
将背景色改为红色
customize UITableView using UITableViewCell
为你的iPhone程序选择颜色

 

步骤 9: 按下 cmd + shift + L ( 或按Tools并选择Library)将text field拖入View 并命名为 “Hello World”。存储文件。

customize UITableView using UITableViewCell
将label拖入到 hello world 的View中

customize UITableView using UITableViewCell
添加label(标签)到view中

customize UITableView using UITableViewCell
改变lable的文字

 

步骤 10: 再次打开Xcode。按“ Build and Go”。你的程序就运行在iPhone模拟器上了。

customize UITableView using UITableViewCell
简单的Hello world iPhone程序输出

 

获取源码

 

这里下载源码。

 

原文见:Getting Started with iPhone Development