zoukankan      html  css  js  c++  java
  • 视图传值

    1.简单方式

      使用UiViewController的两个属性获取源视图控制器和目标视图控制器:

        1.presentingViewController :

                      (ViewController *)self.presentingViewController.<属性名>;

        2.presentedViewController:

                      (ViewController *)self.presentedViewController.<属性名>;

    2.委托

      委托使用@protocol的方式实现,又称为协议。

      首先定义一个委托MyDelegate传值

    @protocol   myDeleget<NSObject>
    -(void)setAViewValue:(NSString *)textValue;
    @end

      在接受数据的视图类中添加协议

    @interface AViewController : UIViewController<myDeleget>
    
    @end

      在AViewController.m文件中实现协议中的方法

    setAViewValue:(NSString *)textValue
    
    {
     
       NSLog(@"%@",_textString);
    
        //A视图中被修改的属性
        _emailtext.text=textValue;
    
      
     }

      在传递数据的bViewController类中定义

      

    @property(nonatomic,assign)  id<myDeleget> deleget;

      在接受数据类AViewController中将自身self委托

    -(void)senderTouch:(id)sender
    {
       
         _BView=[[bViewController alloc] init];
       
         _BView.deleget=self;
       
         [_BView.view setBackgroundColor:[UIColor whiteColor]];
      
          NSLog(@"%@",_BView.deleget);
       
         [self presentViewController:_BView animated:YES completion:^{
            
        }];
      
     }

      bViewController.m返回事件中实现委托

    -(void)BackTouch:(id)sender
    {
        if (_deleget != nil) {
            
            [_deleget setAViewValue:_bViewText.text];
            [self dismissViewControllerAnimated:YES completion:^{
                
                NSLog(@"%@",_bViewText.text);
            }];
        }
        
    }
  • 相关阅读:
    C#后台解析XML字符串并获取节点值
    table动态添加tr
    时间段检索时间段
    什么是数据结构
    PERSONAL VALUES
    C#接口
    基于ArcEngine与C#的鹰眼地图实现
    ENVI/IDL与ArcGIS集成开发的三种途径
    中国地图投影(实现Lambert投影)
    Git 的下载
  • 原文地址:https://www.cnblogs.com/air-liyan/p/4242777.html
Copyright © 2011-2022 走看看