zoukankan      html  css  js  c++  java
  • 封装Tatget Action

    @interface Sample : NSObject {

        SEL action;
        id  target;
       
    }
    @property SEL action;
    @property (assign) id target;

    -(void)addTarget:(id) t action:(SEL) s;
    -(void)sample_dosomthing;

    @end
    -----------------------------------

    #import "Sample.h"
    @implementation Sample

    @synthesize action;
    @synthesize target;


    -(void)dealloc{
        target = nil;
        [super dealloc];
    }

    -(void)addTarget:(id) t action:(SEL) s{
        self.action = s;
        self.target = t;
    }


    -(void)sample_dosomthing{
       
        [self.target performSelector:self.action];
    }

    @end

    =======

    @interface Other : NSObject {

    }

    -(void)other_dosomthing;
    @end

    -------------------------

    #import "Other.h"


    @implementation Other

    -(void)other_dosomthing{
        NSLog(@"other_dosomthing");
    }

    @end

    =============

    Sample *sample1 = [Sample new];
        [sample1 addTarget:self action:@selector(control_dosomthing)];
       
        [sample1 sample_dosomthing]; //SEE LOG
       
        [sample1 release];
       
        //////////////////////////////////////////////////////////////////
       
        Sample *sample2 = [Sample new];
        Other *other = [Other new];
        [sample2 addTarget:other action:@selector(other_dosomthing)];
       
        [sample2 sample_dosomthing]; //SEE LOG
       
        [other release];
        [sample2 release];

     


    作者:GangWang
    出处:http://www.cnblogs.com/GnagWang/
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

     
  • 相关阅读:
    Vue的响应式和双向绑定的实现
    JS-跨域请求豆瓣API提供的数据
    豆瓣电影API接口
    JS/PHP-表单文件域上传文件和PHP后台处理
    jQuery-attr,prop及自定义属性
    PHP-关于php代码和html,js混编
    JS-Chrome控制台console.log会访问即时数据
    JS-time和timeEnd
    JS-用ID值直接操作DOM
    CSS-07 行内设置点击事件
  • 原文地址:https://www.cnblogs.com/GnagWang/p/2176340.html
Copyright © 2011-2022 走看看