IOS中delegate的使用方法

2021-06-07 19:32:06 字數 1383 閱讀 9823

寫了乙個簡單的委託的試用測試:

首先建立functiontest類,宣告委託:

functiontest.h

//

// functiontest.h

// delegatedemo

//// created by shx on 12-7-17.

//#import @protocol functiontestdelegate;

@inte***ce functiontest : nsobject

@property (nonatomic, assign)iddelegate;

- (void)func1;

- (void)func2;

@end

@protocol functiontestdelegate - (void)func3;

- (void)func4;

@end

functiontest.m

//

// functiontest.m

// delegatedemo

//// created by shx on 12-7-17.

//#import "functiontest.h"

@implementation functiontest

@synthesize delegate;

- (void)func1

- (void)func2

@end

//

// delegatedemo

//// created by shx on 12-7-17.

//#import #import "functiontest.h"

@class viewcontroller;

functiontest *test;

}@property (strong, nonatomic) uiwindow *window;

@property (strong, nonatomic) viewcontroller *viewcontroller;

@end

#pragma mark -functiontestdelegate

- (void)func3

- (void)func4

test = [[functiontest alloc]init];

test.delegate = self;

[test func1];

[test func2];

到這裡,delegate就寫完了。

iOS中delegate(委託)的使用

委託 委託,就是委託他人幫自己去做什麼事。也就是當自己做什麼事情不方便的時候,就可以建立乙個委託,這樣就可以委託他人幫自己去實現什麼方法。舉例 這個週末放假有空,我想買個手機,所以我有個buyiphone 方法,但是我不知道誰能買手機,所以把這個需求發布出去 比如公布在 上 如果有賣手機的商人 也就...

ios中關於delegate(委託)

ios中關於delegate 委託 的使用心得 直覺 從開始從事oc工作到現在大概1年多了,從當初接觸oc的 協議 的不明白,到現在 中隨處可見的委託,協議,其中感悟頗多。首先,大家應該都明白的是委託是協議的一種,顧名思義,就是委託他人幫自己去做什麼事。也就是當自己做什麼事情不方便的時候,就可以建立...

ios 設定委託delegate

為了進行頁面傳值,也可以用委託的方法。下面以時間控制項為例。1.首先,在.h 檔案設定委託 import protocol datepickerviewdelegate class datepickerview inte ce datepickerview uiview property stron...