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

Objective-C學(xué)習(xí)筆記 利用協(xié)議實(shí)現(xiàn)回調(diào)函數(shù)

移動(dòng)開發(fā) iOS
本文介紹的是Objective-C學(xué)習(xí)筆記 利用協(xié)議實(shí)現(xiàn)回調(diào)函數(shù),主要是以一個(gè)小實(shí)例來實(shí)現(xiàn)函數(shù)的回調(diào),我們來看內(nèi)容。

Objective-C學(xué)習(xí)筆記 利用協(xié)議實(shí)現(xiàn)回調(diào)函數(shù)是本文要介紹的內(nèi)容,主要是實(shí)現(xiàn)一個(gè)顯示文字為測(cè)試的視圖,然后經(jīng)過3秒鐘測(cè)試文字變?yōu)榛卣{(diào)函數(shù)文字。相應(yīng)的截圖如下:

[[37472]] 

[[37473]]

實(shí)現(xiàn)的代碼如下:

定義協(xié)議:

  1. #import <UIKit/UIKit.h>   
  2. @protocol NoteDelegate   
  3. //回調(diào)函數(shù)   
  4. -(void)messageCallBack:(NSString *)string;   
  5. @end 

調(diào)用協(xié)議:

  1. #import <Foundation/Foundation.h>   
  2. #import "NoteDelegate.h"   
  3. @interface ManagerMessage : NSObject {   
  4.     id<NoteDelegate> *noteDelegate;   
  5. }   
  6. @property (nonatomic,retain) id<NoteDelegate> *noteDelegate;   
  7. -(void)startThread;   
  8. @end  
  9.  
  10. #import "ManagerMessage.h"   
  11. @implementation ManagerMessage   
  12. @synthesize noteDelegate;   
  13. //開始一個(gè)線程   
  14. -(void)startThread   
  15. {   
  16.  
  17.     [NSTimer scheduledTimerWithTimeInterval:3   
  18.                                      target:self   
  19.                                    selector:@selector(targetMethod:)   
  20.                                    userInfo:nil   
  21.                                     repeats:NO];   
  22. }   
  23. -(void)targetMethod:(NSString *)string   
  24. {   
  25.     if (self.noteDelegate!=nil) {   
  26.         //完成線程 調(diào)用回調(diào)函數(shù)   
  27.         [self.noteDelegate messageCallBack:@"回調(diào)函數(shù)"];   
  28.         }   
  29. }   
  30. @end 

前臺(tái)頁(yè)面實(shí)現(xiàn):

  1. #import "IphoneDeleteViewController.h"   
  2. #import "ManagerMessage.h"   
  3. @implementation IphoneDeleteViewController   
  4. @synthesize textView;   
  5.  
  6. //回調(diào)函數(shù)   
  7. -(void)messageCallBack:(NSString *)string   
  8. {   
  9.     self.textView.text=string;   
  10. }   
  11. - (void)viewDidLoad {   
  12.     [super viewDidLoad];   
  13.     self.textView.text=@"測(cè)試";   
  14.     ManagerMessage *message=[[ManagerMessage alloc] init];   
  15.     //通知調(diào)用協(xié)議   
  16.     message.noteDelegate=self;   
  17.     [message startThread];   
  18.     [message release];   
  19. }   
  20. - (void)didReceiveMemoryWarning {   
  21.     [super didReceiveMemoryWarning];   
  22. }   
  23. - (void)viewDidUnload {   
  24.     self.textView=nil;   
  25. }   
  26. - (void)dealloc {   
  27.     [self.textView release];   
  28.     [super dealloc];   
  29. }   
  30. @end 

小結(jié):Objective-C學(xué)習(xí)筆記 利用協(xié)議實(shí)現(xiàn)回調(diào)函數(shù)的內(nèi)容介紹完了,希望本文對(duì)你有所幫助。

責(zé)任編輯:zhaolei 來源: 互聯(lián)網(wǎng)
相關(guān)推薦

2011-08-04 14:58:37

Objective-C Cocoa NSString

2011-08-05 14:03:39

Objective-C 對(duì)象 模板

2011-08-16 10:23:04

Objective-CNSAutoreleaXcode常用鍵

2013-06-20 10:40:32

Objective-C實(shí)現(xiàn)截圖

2011-08-15 16:09:44

Cocoa對(duì)象Objective-C

2011-07-27 16:36:03

iphone Objective- 靜態(tài)庫(kù)

2011-07-22 15:42:39

Objective-C UIView 內(nèi)存

2011-08-04 11:15:46

Objective-C 構(gòu)造函數(shù) 構(gòu)造方法

2011-08-03 15:51:48

Objective-C 協(xié)議 委托

2011-08-17 10:58:59

Objective-C構(gòu)造函數(shù)

2013-04-11 13:41:30

Objective-CiOS編程

2013-08-21 14:57:42

objective-c問題

2011-05-11 14:06:49

Objective-C

2011-08-04 11:04:14

Objective-C 面向?qū)ο? 繼承

2011-08-04 10:38:17

Objective-C 預(yù)處理程序

2011-08-22 15:31:35

Objective-C協(xié)議

2011-08-15 14:32:42

Objective-C委托協(xié)議

2011-08-15 17:29:36

Objective-C構(gòu)造函數(shù)

2011-07-27 16:18:42

Objective-c 協(xié)議

2011-07-25 10:03:06

Objective-C 委托
點(diǎn)贊
收藏

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