zoukankan      html  css  js  c++  java
  • objective处委托协议

    满足正式协议  protocol 的委托只能执行协议中的方法,

    #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  中的一切方法,也可以调用其的属性变量

     
  • 相关阅读:
    封装好的AFN网络请求框架和MBProgress
    iOS定时器的使用
    iOS去除导航栏和tabbar的1px横线
    移动端加解密
    改变字符串中部分字符传的字体大小和颜色
    关于NSLog
    ipad开发:二维码扫描,摄像头旋转角度问题解决办法
    iOS-图文表并茂,手把手教你GCD
    计算富文本的高度
    jsp打印
  • 原文地址:https://www.cnblogs.com/pengyingh/p/2509067.html
Copyright © 2011-2022 走看看