自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Objective-C學(xué)習(xí)文檔之協(xié)議使用方法

移動開發(fā) iOS
Objective-C學(xué)習(xí)文檔之協(xié)議使用方法是本文要介紹的內(nèi)容,主要是來了解并學(xué)習(xí)Objective-C中協(xié)議的問題,具體內(nèi)容來看本文內(nèi)容詳解。

Objective-C學(xué)習(xí)文檔之協(xié)議使用方法是本文要介紹的內(nèi)容,主要是來了解并學(xué)習(xí)Objective-C中協(xié)議的問題,具體內(nèi)容來看本文內(nèi)容詳解。

一、協(xié)議的定義

  1. @protocol test  
  2. -(void) testpocol:(int)t;  
  3. @end 

二、協(xié)議的繼承

h頭文件

  1. #import “test.h”    //導(dǎo)入?yún)f(xié)議  
  2. @interface testViewController:UIViewController <test>{  
  3. //id<test> testp;  

m實現(xiàn)文件

  1. @implementation testViewController  
  2. -(void)viewDidLoad{  
  3. [super viewDidLoad];  
  4. //調(diào)用實現(xiàn)方法的類  
  5. testdiaoyong  *td=[[testdiaoyong alloc] init];  
  6. td.testd=self;   把當(dāng)前實現(xiàn)協(xié)議的類對象賦給需要使用的地方  
  7. //也可以使用下面的方法傳遞協(xié)議  
  8. [td  setpoco:self]  
  9. }  
  10. -(void) testpocol:(int)s{  
  11.  
  12. NSLog(@"testpocol.........%d",s);  
  13. }  
  14. @end 

三、調(diào)用協(xié)議

  1. @interface testdiaoyong  : NSObject{  
  2. id<test> testp;  
  3. }  
  4. -(void)setpoco:t;  
  5. -(void)setlen;  
  6. @end  
  7. @implementation testdiaoyong  
  8. @synthesize testp;  
  9. //協(xié)議t可以不負(fù)類型  
  10. -(void)setpoco:t{  
  11. self.testp=t;  
  12. }  
  13. -(void)start{  
  14. [testp testpocol:99];  
  15. }  
  16.  
  17. @end 

小結(jié):Objective-C學(xué)習(xí)文檔之協(xié)議使用方法的內(nèi)容介紹完了,希望通過本文的學(xué)習(xí)能對你有所幫助!

責(zé)任編輯:zhaolei 來源: 網(wǎng)絡(luò)轉(zhuǎn)載
相關(guān)推薦

2011-08-15 17:06:01

Objective-CNSLog

2011-08-04 16:46:03

Objective-C 聲明

2011-08-12 10:27:52

Objective-C對象

2011-07-19 17:18:35

Objective-C Property

2011-08-02 15:55:31

Objective-C NSAutorele

2011-08-10 17:16:01

Objective-C靜態(tài)變量

2013-08-21 13:26:43

Objective-CNSDate說明

2011-07-27 16:18:42

Objective-c 協(xié)議

2011-08-10 11:08:32

Objective-C字符串NSString

2011-08-17 11:05:22

Objective-C方法

2011-07-25 10:14:13

Objective-C Xcode

2011-07-25 10:30:41

Objective-C Xcode 重構(gòu)

2011-07-25 11:02:29

Objective-C Xcode 標(biāo)簽

2011-08-03 15:51:48

Objective-C 協(xié)議 委托

2011-08-17 12:03:36

Objective-C

2011-07-28 15:11:23

iOS Objective-

2011-08-16 10:23:04

Objective-CNSAutoreleaXcode常用鍵

2011-08-04 14:58:37

Objective-C Cocoa NSString

2013-08-21 14:57:42

objective-c問題

2011-05-11 14:06:49

Objective-C
點贊
收藏

51CTO技術(shù)棧公眾號