• Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
651
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
0
Comments
0
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. iPhone Development How-To Lesson2. 第一個結構化程式 Step1.Create a new Xcode project Step2.Mac OS X ->Application -> Command Line Tool -> Foundation
  • 2. Step3.輸入專案名稱,Save
  • 3. Step4.在 Source 資料夾上按右鍵,Add -> New File… Step5.Cocoa Touch Class -> Objective-C class -> NSObject,Next
  • 4. Step6.命名
  • 5. Step7.在 fraction.h 中進行修改, .h 檔負責存放@interface 區段: 1. 宣告一個新的類別,並指出此類別的父類別是誰 2. 描述此類別有哪些資料成員 3. 定義方法(method) 備註: A. Fraction 繼承自 NSObject 類別 B. Fraction 有兩個整數變數:numerator, denominator C. –(void) setNumerator:( int)n; 減號代表實體方法,加號代表類別方法 void 代表該方法沒有傳回值 setNumerator 接收一個整數參數,參數名稱為 n Step8.修改 Fraction.m 撰寫 print, setNumerator, setDenominator 方法的內容
  • 6. 9.撰寫主程式 function0615.m #import <Foundation/Foundation.h> #import "Fraction.h" int main (int argc, const char * argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; Fraction *myFraction;//宣告一個Fraction物件 myFraction=[[Fraction alloc]init];//分配記憶體與初始化 [myFraction setNumerator:1]; //執行setNumerator方法,並傳入1 [myFraction setDenominator:3];//執行setDenominator方法,並傳入3 NSLog(@"The value of myFraction is:");//於Console視窗顯示字串 [myFraction print];//執行print方法,會顯示出結果 [myFraction release];//釋放記憶體 [pool drain]; return 0; }
  • 7. 10.Build -> Build & Debug,然後點選 Run -> Console 觀看執行結果