zoukankan      html  css  js  c++  java
  • 代理的定义及使用

    1.在需要把数据传到外面的地方申明代理

    @protocol NextViewControllerDelegate <NSObject>

    2.声明代理方法

    - (void)didLoadDataWithMessage:(NSString *)message;//定义或申明

    @end//对应@protocol

    一般代理定义在  #import<UIKit/UIKit.h>  至  @interface之间

    3.定义属性   实现代理方可以通过这个属性  找到这个代理(较难理解)

    @property (nonatomic, assign)id<NextViewControllerDelegate>delegate;//NextViewControllerDelegate为你的代理名

    4.代理一般用于传值,在需要传值的地方调用代理

     [self.delegate didLoadDataWithMessage:@"hehehe"];//将hehehe传给实现代理的地方

    5.在需要传值的地方  引入代理  @interface ViewController ()<NextViewControllerDelegate>

    6.定义变量,挂上代理(用声明代理的类,定义对象,挂上代理)

     NextViewController *nextView = [[NextViewController alloc]init];

    //    5.挂上代理

        nextView.delegate = self;

    7.实现代理方法  接收传过来的值

    - (void)didLoadDataWithMessage:(NSString *)message{

        NSLog(@"%@",message);

        label.text = message;

    }

    最后希望看到这篇文章的人多评论,以便改善,当然我不介意大家关注我,大家一起学习,一起进步,谢谢!

    为了更好点交流和学习,请大家在参阅博客后,留下你的疑问和宝贵意见。谢谢!!!!
  • 相关阅读:
    ‘Host’ is not allowed to connect to this mysql server
    centos7安装mysql
    further configuration avilable 不见了
    Dynamic Web Module 3.0 requires Java 1.6 or newer
    hadoop启动 datanode的live node为0
    ssh远程访问失败 Centos7
    Linux 下的各种环境安装
    Centos7 安装 python2.7
    安装scala
    Centos7 安装 jdk 1.8
  • 原文地址:https://www.cnblogs.com/fshmjl/p/4822245.html
Copyright © 2011-2022 走看看