鍍金池/ 教程/ iOS/ iOS - 創(chuàng)建第一個(gè)iPhone應(yīng)用
iOS - Switches(切換/開關(guān))
iOS - Labels(標(biāo)簽)
iOS - Table View(表格視圖)
IOS - 攝像頭管理
iOS - Text View(文本視圖)
IOS - 開發(fā)環(huán)境配置
iOS教程
iOS - Twitter & Facebook
iOS - UI元素
iOS - iAd 整合
IOS - 應(yīng)用程序調(diào)試
iOS - Split View(分割視圖)
iOS - Status Bar(狀態(tài)欄)
iOS - Navigation Bar(導(dǎo)航欄)
iOS - Tab bar(標(biāo)簽欄)
IOS - 文件處理
IOS - 自動(dòng)布局
iOS - Image View(圖像視圖)
iOS - 應(yīng)用程序內(nèi)購(gòu)買
iOS - Pickers(選取器)
iOS - Delegates實(shí)例
iOS - 創(chuàng)建第一個(gè)iPhone應(yīng)用
iOS (iPhone, iPad)教程
iOS - 發(fā)送電子郵箱(Email)
iOS - View Transitions(視圖轉(zhuǎn)換)
iOS - 內(nèi)存管理
iOS - Icons(圖標(biāo))
iOS - 音頻和視頻
iOS - Storyboards(演示圖板演)
iOS - Buttons(按鈕)
iOS - Text Field(文本域)
iOS - Sliders(滑動(dòng)條)
iOS - Scroll View(滾動(dòng)視圖)
IOS - 輸入類型 文本字段
iOS - 位置處理
iOS - Accelerometer(加速度傳感器)
IOS - 快速入門
iOS - SQLite 數(shù)據(jù)庫(kù)
iOS - GameKit
IOS - 訪問地圖
iOS - Objective-C基礎(chǔ)
iOS - Toolbar(工具欄)
IOS - 動(dòng)作和插座(Outlets)
iOS - Alerts(警示)
IOS - 通用應(yīng)用程序

iOS - 創(chuàng)建第一個(gè)iPhone應(yīng)用

創(chuàng)建第一個(gè)iPhone應(yīng)用

現(xiàn)在,我們只是要?jiǎng)?chuàng)建一個(gè)簡(jiǎn)單的單視圖的應(yīng)用程序(一個(gè)空白的應(yīng)用程序),只運(yùn)行在iOS模擬器。

步驟如下。

1. 打開Xcode和選擇創(chuàng)建一個(gè)新的Xcode項(xiàng)目。

2. 然后選擇單一視圖應(yīng)用

3. 然后輸入項(xiàng)目名稱,即應(yīng)用程序的名稱,組織名稱和公司標(biāo)識(shí)

4. 確保使用自動(dòng)引用計(jì)數(shù)的選擇,以便自動(dòng)釋放分配的資源,一旦超出范圍。單擊 Next.

5. 選擇項(xiàng)目的目錄,并選擇create.

6. 你會(huì)看到如下的一個(gè)屏幕

在屏幕上方你將能夠選擇支持的方向,建立和釋放設(shè)置?,F(xiàn)場(chǎng)部署有一個(gè)目標(biāo),我們要支持設(shè)備版本,選擇4.3這是現(xiàn)在最小允許部署目標(biāo)?,F(xiàn)在這些都不是必需的,讓我們把注意力集中在運(yùn)行的應(yīng)用程序。

7. 現(xiàn)在選擇iPhone模擬器在附近運(yùn)行按鈕的下拉,選擇“run”。 

8. 已經(jīng)成功地運(yùn)行第一個(gè)應(yīng)用程序。會(huì)得到一個(gè)輸出如下

現(xiàn)在讓我們來改變背景顏色,只是為了有一個(gè)開始界面生成器。選擇ViewController.xib。選擇“background ”選項(xiàng),在右側(cè),改變顏色并運(yùn)行。

在上述項(xiàng)目中,默認(rèn)情況下部署目標(biāo)已設(shè)定到 iOS6.0,自動(dòng)布局將啟用。但是,為了確保我們的應(yīng)用程序運(yùn)行的設(shè)備上運(yùn)行的iOS 4.3開始,我們已經(jīng)修改了部署目標(biāo)在創(chuàng)建這個(gè)應(yīng)用程序的開始,但我們沒有禁用自動(dòng)布局,禁用自動(dòng)布局,我們需要取消選擇“自動(dòng)布局xib文件的每個(gè) nib,即在 inspector 復(fù)選框。 Xcode項(xiàng)目IDE的各個(gè)部分是下圖中(注:蘋果 Xcode4 用戶文檔)。

文件檢查器處于找到檢查器選擇欄中,如上圖所示,自動(dòng)布局可以是取消選中。當(dāng)想只針對(duì)的iOS6設(shè)備,可用于自動(dòng)布局。此外,將能夠使用許多新功能,如果提高到iOS6部署目標(biāo)。這里使用 iOS4.3 部署目標(biāo)。

深入挖掘的第一個(gè)iOS應(yīng)用程序的代碼

會(huì)發(fā)現(xiàn)5個(gè)不同的文件,將已生成的應(yīng)用程序,如下。

  • AppDelegate.h

  • AppDelegate.m

  • ViewController.h

  • ViewController.m

  • ViewController.xib

我們使用這些單行注釋(/ /)給下面的代碼解釋簡(jiǎn)單的代碼解釋和重要的項(xiàng)目。

AppDelegate.h

// Header File that provides all UI related items. 
#import <UIKit/UIKit.h> 
 // Forward declaration (Used when class will be defined /imported in future)
@class ViewController;  

 // Interface for Appdelegate
@interface AppDelegate : UIResponder <UIApplicationDelegate>
// Property window 
@property (strong, nonatomic) UIWindow *window; 
 // Property Viewcontroller
@property (strong, nonatomic) ViewController *viewController;
//this marks end of interface 
@end  
重要項(xiàng)目代碼
  • AppDelegate中繼承自UIResponder的處理??的iOS事件

  • 實(shí)現(xiàn) UIApplication委托的委托方法提供關(guān)鍵的應(yīng)用程序事件等成品發(fā)起,終止等。

  • 一個(gè)UIWindow對(duì)象來管理和協(xié)調(diào)各方面的意見在iOS設(shè)備上屏幕。這就像所有其他加載意見的基礎(chǔ)視圖。在一般情況下只有一個(gè)應(yīng)用程序的一個(gè)窗口。

  • UIViewController 處理??畫面流暢。

AppDelegate.m

// Imports the class Appdelegate's interface
import "AppDelegate.h" 

// Imports the viewcontroller to be loaded
#import "ViewController.h" 

// Class definition starts here
@implementation AppDelegate 


// Following method intimates us the application launched  successfully 
- (BOOL)application:(UIApplication *)application 
 didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{
    self.window = [[UIWindow alloc] initWithFrame:
	[[UIScreen mainScreen] bounds]]; 
    // Override yiibai for customization after application launch.
    self.viewController = [[ViewController alloc] 
	 initWithNibName:@"ViewController" bundle:nil];
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
    /* Sent when the application is about to move from active to inactive state.
    This can occur for certain types of temporary interruptions
    (such as an incoming phone call or SMS message)
    or when the user quits the application and it begins the transition to the 
    background state. Use this method to pause ongoing tasks, disable timers, 
    and throttle down OpenGL ES frame rates. Games should use this method 
    to pause the game.*/
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    /* Use this method to release shared resources, save user data, invalidate 
    timers, and store enough application state information	to restore your
    application to its current state in case it is terminated later. If your 
    application supports background execution, this method is called instead 
    of applicationWillTerminate: when the user quits.*/
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    /* Called as part of the transition from the background to the inactive state;
    here you can undo many of the changes made on entering the background.*/
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    /* Restart any tasks that were paused (or not yet started) while the
    application was inactive. If the application was previously in the background, 
	optionally refresh the user interface.*/
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    /* Called when the application is about to terminate. Save data if appropriate.
    See also applicationDidEnterBackground:. */
}

@end
重要項(xiàng)目代碼
  • 這里的UIApplication定義的委托。上述定義的所有方法是用戶界面應(yīng)用程序代表和不包含任何用戶定義的方法。

  • UIWindow中分配對(duì)象來保存應(yīng)用程序被分配

  • UIViewController的分配窗口的初始視圖控制器。

  • 為了使窗口的可見makeKeyAndVisible方法被調(diào)用。

ViewController.h

#import  

// Interface for class ViewController
@interface ViewController : UIViewController 

@end
重要項(xiàng)目代碼
  • ViewController 類繼承的UIViewController為iOS應(yīng)用程序提供了基本的視圖管理模式。

ViewController.m

#import "ViewController.h"

// Category, an extension of ViewController class
@interface ViewController ()

@end

@implementation ViewController  

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemory