zoukankan      html  css  js  c++  java
  • 代理设计模式简单格式(备忘)

    A控制器充当B控制器的代理:(B页面的数据反传给A页面进行数据的更新,一般A跳转到B的这种情况下需要使用代理方法)

    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页面进行需要的设置
    }
    

     

  • 相关阅读:
    测试用例编写思路
    pipenv和virtualenv
    HTTP协议
    性能测试实践
    性能测试
    JS创建类和对象
    servlet的转发与重定向
    早晚得看算法
    安卓开始啦
    写于大三下开学前(即将休学)
  • 原文地址:https://www.cnblogs.com/yipingios/p/5615443.html
Copyright © 2011-2022 走看看