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{

    }

      
  • 相关阅读:
    SqlServer 查看数据库中所有存储过程
    SqlServer 查看数据库中所有视图
    SqlServer 查询表的详细信息
    SqlServer 遍历修改字段长度
    net core 操作Redis
    Tuning SharePoint Workflow Engine
    Open With Explorer
    Download language packs for SharePoint 2013
    Change Maximum Size For SharePoint List Template when Saving
    Six ways to store settings in SharePoint
  • 原文地址:https://www.cnblogs.com/sgdkg/p/2715427.html
Copyright © 2011-2022 走看看