委托代理(degegate)的理解和使用示例
来源:互联网 发布:菜刀连接数据库 编辑:程序博客网 时间:2024/05/28 17:06
什么是代理,如何实现的?
委托代理(degegate),顾名思义,把某个对象要做的事情委托给别的对象去做。那么别的对象就是这个对象的代理,代替它来打理要做的事。
SecondPageControl.m
执行方(被委托的):
SecondViewThirdSubViewController.h
SecondViewThirdSubViewController.m
委托代理(degegate),顾名思义,把某个对象要做的事情委托给别的对象去做。那么别的对象就是这个对象的代理,代替它来打理要做的事。
反映到程序中, 首先要明确一个对象的委托方是哪个对象,委托所做的内容是什么。
委托者:
SecondPageControl.h
#import <UIKit/UIKit.h>//委托的声明,设置委托者的名称 =1=@protocol SecondPageControlDelegate <NSObject>-(void)pushControllerTest:(id)dender;//委托者需要实现方法pushControllerTest的声明 =2=@end@interface SecondPageControl : UIViewController<UIScrollViewDelegate>{ .................... .................... .................... id<SecondPageControlDelegate>delegate; //=3=}@property (nonatomic, retain)id<SecondPageControlDelegate>delegate; //=4=@end
SecondPageControl.m
#import "SecondPageControl.h"@interface SecondPageControl...........................................@end@implementation SecondPageControl@synthesize delegate; //=5=//按钮响应事件-(void) btnPressed:(id) sender{ UIButton *myBtn=(UIButton *) sender; if (myBtn.tag == 321)//因为消息不能直接发送到,所以使用代理 { if([delegate respondsToSelector:@selector(pushControllerTest:)]) //委托者需要实现的方法pushControllerTest =6= { [delegate performSelector:@selector(pushControllerTest:) withObject:nil]; } }}
执行方(被委托的):
SecondViewThirdSubViewController.h
#import <UIKit/UIKit.h>@class SecondPageControlDelegate;//=1=@interface SecondViewThirdSubViewController : UIViewController<SecondPageControlDelegate> //=2={ ..........................}@end
SecondViewThirdSubViewController.m
#import "SecondViewThirdSubViewController.h"@implementation SecondViewThirdSubViewController...............................-(void)pushControllerTest:(id)sender //实现被委托的方法=3={ ImageShowController *imageShowView = [[[ImageShowController alloc] init] autorelease]; [self.navigationController pushViewController:imageShowView animated:NO];}@end
- 委托代理(degegate)的理解和使用示例
- IOS开发中委托代理(degegate)的理解和使用示例
- IOS开发中委托代理(degegate)的理解和使用示例
- IOS开发中委托代理(degegate)的理解和使用示例
- IOS中委托代理(degegate)的理解和使用示例
- degegate的理解和使用示例
- degegate的理解和使用示例
- iPhone开发之Delegate(代理、委托)的理解和使用
- iPhone开发之Delegate(代理、委托)的理解和使用
- 代理(委托)的理解
- 委托的理解和使用
- 委托和代理(类似接口回调的使用)
- C#中委托的理解和使用
- c#的委托(代理)和事件
- c#的委托(代理)和事件
- c#的委托(代理)和事件
- c#的委托(代理)和事件
- 快速理解ios的委托协议代理(delegate)
- ios简单使用core data
- redis一些常见常用的配置参数的简单说明
- 获取PE文件自校验值
- 避免QComboBox下拉选项重复的好方法,一试就爽
- intellij创建快捷方式到桌面
- 委托代理(degegate)的理解和使用示例
- 算法学习之数据结构之双向链表
- 第4章 存储器
- centos清理内存命令
- Windows Phone 游戏 Galaga Legions DX 去除 XBL 服务
- JSTL标签的问题(尚学堂OA项目开发阶段)
- hdu 4396 spfa
- 挂载远程文件系统nfs
- java实现各种算法