zoukankan      html  css  js  c++  java
  • iOS protocol传值

      一 、

            1、直接在需要传递数据的文件种声明protocol。

                  A.h//需要传递数据的文件

         @property(retain,nonatomic)id<FinanceStreetDelegate> delegate; 

          @end

          @protocol FinanceStreetDelegate <NSObject>

          -(void)showCreditInfo:(NSString*)userId;

          @end

         A.m中协议的方法,通过参数传递数据

            [self.delegate showCreditInfo:@"23"];

      2、在需要接收数据的文件中实现这个协议 

          B.h中

                      @interface b : UIViewController <FinanceStreetDelegate>

          B.m中 

          A *aa=[[A alloc] init];

           aa.delegate=self;

           -(void)showCreditInfo:(NSString*)userId{
            //userId 就是传过来的值。 
          }  
     
     
    二 、直接创建一个protocol文件。
           

     1、创建protocol

    #import <Foundation/Foundation.h>

     //PopTableAction.h

    @protocol PopTableAction <NSObject>

    -(void)doTableResult:(NSString*)resultInfo;

    @end

    2、传递数据

         A.h

    #import "PopTableAction.h"

    @interface A : UIViewController

    @property (nonatomic,assign) id<PopTableAction>delegate;

    @end

    A.m中//比如在tableview的方法中

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

             NSString *selectedCellText =@"sa";

              [self.delegate doTableResult:selectedCellText];

    }

    2、实现protocol,取得数据
       B.h

    @interface B : UIViewController<PopTableAction

     
      B.m中;
       A *a;
      a.delegate=self;
      

    -(void)doTableResult:(NSString*)resultInfo{

    }

      
  • 相关阅读:
    浏览器基本的工作原理
    ES6异步操作之Promise
    vux中x-input在安卓手机输入框的删除按钮(@on-click-clear-icon)点击没反应
    浏览器工作原理
    form表单的两种提交方式,submit和button的用法
    HTML DOM submit() 方法
    JavaScript test() 方法
    eval() 函数
    正则表达式
    onblur 事件
  • 原文地址:https://www.cnblogs.com/sgdkg/p/2715427.html
Copyright © 2011-2022 走看看