IOS學習筆記一

來源:互聯網
上載者:User

標籤:一個   soho   xxx   inter   lock   學習筆記   turn   react   ram   

//建立.h檔案  介面的類檔案(建立一個類)

@interface MyClass:NSObject{

//類變數聲明

int a;

int b;

}

//類屬性聲明

(int) p2 

//類方法聲明

-(return_type)method_one;

-(return_type)method_two:(int) p1;

//靜態方法

+(void)sayHello;

 

@end

 

//執行檔案 .m檔案 

@implementation MyClass {

int c;

}

//類方法定義:

  -(return_type)method_one{

  //

  }

 //靜態方法的實現,不需要實力化就可以調用

  +(void)sayHello{

  NSLog(@"hello");

 

  }

@end

使用靜態:[MyClass sayHello];

使用實力化方法

 mynew=[MyClass new]

 [mynew method_one]

 

區別: .h檔案代表的是標頭檔,用來申明各種類裡面的成員變數和方法以及屬性等等  在import的時候用用標頭檔

      .m檔案 主要是用來實現.h檔案裡面申明的方法 

      ep:

         在.h檔案申明一個方法: 

                -(void)myMethod;

          在.m檔案裡面具體實現

                -(void)myMethod{

                NSLog(@"this is my new method");

                }

 

 

帶參數的方法

-(void)setColorTored:(float)red Green:(float)green Blue:(float)blue{

 

}

調用

[myObj setColorTored:1.0 Green:0.8 Blue:0.2]

 

 

2:類

介面和實現

OC的類分為介面定義和實現兩個部分,介面(interface)定義放在標頭檔中,拓展名稱是.h 

實現(implementation)放在實現檔案中 拓展名是.m檔案 這裡注意的是介面和實現是一一對應的

 

3:import標頭檔

   #import "xxx.h" 引用庫

   #import "<React/reactxxx.h>" 引用framework架構

 

4OC+架構cocoaTouch+IDE

 參考文章:http://www.cnblogs.com/wellsoho/p/4313312.html

IOS學習筆記一

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.