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);
            }];
        }
        
    }
  • 相关阅读:
    Android之基于XMPP即时通讯(转)
    开机启动service小DEMO
    Android 歌词同步滚动效果(转)
    OC中的消息传递和初始化
    oc中对象的初始化
    c语言的结构体字节数统计
    css的页面布局
    说一说我理解的css
    什么是js闭包
    我对js作用域的理解
  • 原文地址:https://www.cnblogs.com/air-liyan/p/4242777.html
Copyright © 2011-2022 走看看