首页 > 其他 > 详细

代理的使用

时间:2015-04-11 20:43:24      阅读:162      评论:0      收藏:0      [点我收藏+]

MyView.h

 @protocal ViewTouchDelegate<NSObject>

  @required

  -(void)touchMyView;

 @end

 

{

  id<ViewTouchDelegate>delegate;

}

@property (nonamtic,assign)id<ViewTouchDelegate>delegate;

 

-(void)touchMyView;

 

 

MyView.m

-(id)init

{

  self =[super init];

  if(self)

       {

      [self touchMyView];

       }     

  return self;

}

 

-(void)touchMyView

{

  delegate =_delegate;

 

  if([_delegate conformsToProtocal:@protocal(ViewTouchDelegate)])

  {

    if([_delegate respondsToSelector:@selector(touchMyView)])

    {

      [_delegate touchMyView];

            }

       }

}

 

 

MyViewController.h

#import "MyView.h"

@interface MyViewController:UIViewController <ViewTouchDelegate>

 

MyViewController.m

-(void)viewDidLoad

{

  [super viewDidLoad];

  MyView *_myView =[[MyView alloc]init];

  _myView.frame =CGRectMake(0,0,100,100);

  _myView.delegate=self;

  [self.view addSubView:_myView];

}

 

-(void)touchMyView

{

  NSLog(@"Delegate is doing things");

}

 

代理的使用

原文:http://www.cnblogs.com/520myp1314/p/4418262.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!