objective-处委托协议
2012-05-19 18:30
447 查看
满足正式协议 protocol 的委托只能执行协议中的方法,
注:如果 delegate 不满足协议,直接传递 GameBoardController指针
则delegate 可以执行 GameBoardController 中的一切方法,也可以调用其的属性变量
#import <Foundation/Foundation.h>@protocol GameBoardControllerDelegate <NSObject> @optional - (NSInteger)getColumns; - (NSInteger)getRows; @end
#import "cocos2d.h" #import "GameBoardControllerDelegate.h" //MVC中的C @class GameBoard; @class GameBoardView; @interface GameBoardController : CCNode <GameBoardControllerDelegate> { GameBoardView *_view; } @property(nonatomic,retain) GameBoard *gameBoard; //MVC中的M @property(nonatomic,retain) GameBoardView *view; //MVC中的V - (NSInteger)getColumns; - (NSInteger)getRows; @end
#import "cocos2d.h" #import "GameBoardControllerDelegate.h" @interface GameBoardView : CCNode { id <GameBoardControllerDelegate>_delegate; //满足正式协议的传过来的 GameBoardController指针
} @property(nonatomic,assign)id <GameBoardControllerDelegate> delegate; - (void)initView; @end
#import "GameBoardView.h" @implementation GameBoardView @synthesize delegate = _delegate; - (void)initView { for (int i = 0; i <[_delegate getRows]; i++) { for (int j = 0; j< [_delegate getColumns] ; j++) { // position and render game board spaces } } } @end
注:如果 delegate 不满足协议,直接传递 GameBoardController指针
则delegate 可以执行 GameBoardController 中的一切方法,也可以调用其的属性变量
相关文章推荐
- Objective-C 委托、非正式协议、正式协议
- Objective-c 协议与委托
- 详解Objective-C中委托和协议
- 详解Objective-C中委托和协议
- objective-c 协议和委托
- objective-c 协议和委托
- Objective-C 中protocol(协议)及delegate(委托、代理)
- objective-c 委托与协议
- Objective-C中的协议和代理(委托)设计模式
- Objective-C 协议 简介 +委托的实现
- Objective-C中的“委托(delegate)”和“协议(protocal)”
- Objective-C 协议 简介 +委托的实现
- Objective-C中协议和委托简述
- objective-c 协议与委托
- Objective-C ,ios,iphone开发基础:protocol 协议(委托,代理)的声明
- Objective-C中协议和委托
- Objective-C中委托和协议
- Objective-C 协议 简介 +委托的实现
- Objective-C中协议和委托
- Objective-C协议(protocol)和委托(delegate)的基本概念