代理设计模式简单格式(备忘)
2016-06-24 22:03
351 查看
A控制器充当B控制器的代理:(B页面的数据反传给A页面进行数据的更新,一般A跳转到B的这种情况下需要使用代理方法)
B控制器.h文件中的代码如下:
B控制器.m文件中的代码如下:
A页面需要实现相应的代理,和代理方法,.m文件中的代码如下
B控制器.h文件中的代码如下:
#import <UIKit/UIKit.h> @protocol SearchDestinationDelegate <NSObject> - (void)searchDestinationWithLocation:(CLLocationCoordinate2D)secrchLocationCoordinate; @end @interface SearchDestinationVC : UIViewController @property (nonatomic, weak) id<SearchDestinationDelegate> searchLocationDelegate; @end
B控制器.m文件中的代码如下:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if ([self.searchLocationDelegate respondsToSelector:@selector(searchDestinationWithLocation:)]) { [self.searchLocationDelegate searchDestinationWithLocation:self.endUserLocation]; } [self.navigationController popViewControllerAnimated:YES]; }
A页面需要实现相应的代理,和代理方法,.m文件中的代码如下
//跳转到B页面的时候,让A页面充当B页面的代理<SearchDestinationDelegate> SearchDestinationVC *searchVC = [[SearchDestinationVC alloc]init]; searchVC.searchLocationDelegate = self; [self.navigationController pushViewController:searchVC animated:NO]; //实现代理中的方法 -(void)searchDestinationWithLocation:(CLLocationCoordinate2D)secrchLocationCoordinate { //拿到B页面穿过来的数据,在A页面进行需要的设置 }
相关文章推荐
- 大数据
- 详解Android中AsyncTask的使用
- Nim游戏 Nim Game
- C++ Primer Plus 第六版_编程练习(1)(Chapter_two 1-7)
- Java内存区域与内存溢出异常
- Git & Github建立与使用
- 组织能力下行
- 0624软件工程的回顾和总结
- 软件工程学期总结
- JAVA——管道流
- Linux 给history加时间戳
- Java内存区域与内存溢出异常
- SQL Server Extended Events 进阶 1:从SQL Trace 到Extended Events
- 基于正则表达式的数据抓包
- UNIX网络编程笔记(7)—名字与地址转换
- Activity启动模式
- SevletContext
- Mybatis与Hibernate的详细对比
- Mybatis与Hibernate的详细对比
- 【转载】聊聊高并发系统之降级特技