zoukankan      html  css  js  c++  java
  • 笔记

    1、属性传值

    前向后传值。

    记住:

    /*

    1: 属性传值第一步需要用到什么类型就定义什么样的属性 

    2: 从上一个页面到一个页面的选中方法里面将要传的值传到来(上一个页面)备注:这种方法只适用于上一个页面推到下一个页面 

    */

    MainViewController与SecondViewController两个视图  控制器 ,点击MainViewController中的按钮将跳转到SecondViewController视图,同时想要传递一个值过去。这时可以利用属性传值。 

    首先SecondViewController视图中需要有一个属性用来  存储 传递过来的值: 

    @property(nonatomic,retain) NSString *firstValue ;//属性传值

    然后MainViewController视图需要引用SecondViewController视图的头文件,在视图中的按钮点击事件中,通过SecondViewController的对象将需要传递的值存在firstValue中:

    (void)buttonAction:(UIButton *)button
    
    {SecondViewController *second = 
    [[SecondViewController alloc]init];//用下一个视图的属性接受想要传过去的值,属性传值
    
    second.firstValue = _txtFiled.text;
    
    [self.navigationController pushViewController:second animatedS];面跳转之后,就能在SecondViewController视图中,通过存值的属性,取用刚才传递过来的值:
    //显示传过来的值[_txtFiled setText:_firstValue];//firstValue保存传过来的值
    

    2、方法传值:

         需求同一中的  属性传值 一样,但是要通过使用方法传值,可以直接将方法与初始化方法合并,此时当触发MainViewController的按钮点击事件并跳转到SecondViewController时,在按钮点击事件中可以直接通过SecondViewController的初始化,将值保存在firstValue中: 

    初始化方法如下:                 首先SecondViewController视图中需要有一个属性用来 存储 传递过来的值: 

    @property(nonatomic,retain) NSString *firstValue ;//传值用

    //重写初始化方法,用于传值
    
    - (id)initWithValue:(NSString *)value
    
    {
    
    if(self = [super initWithNibName:nil bundle:nil]) {
    
                     self.firstValue = value;
    
                }
    
            return self;
    
    }
    

    方法传值:

    - (void)buttonAction:(UIButton *)button
    
    {//将方法传值与初始化写到一起
    
    SecondViewController *second = [[SecondViewController alloc]
    
    initWithValue:_txtFiled.text];//此时已经将值存在firstValue中
    
    [self.navigationController pushViewController:second animated:YES];
    
    }
    

    这样就可以直接通过firstValue属性获得传递过来的值:

    //显示传过来的值[_txtFiled setText:_firstValue];//firstValue保存传过来的值
    
  • 相关阅读:
    TBDR下msaa 在metal vulkan和ogles的解决方案
    Load store action in vulkan & ogles 的解决方案
    百度 我日你全家
    metal sample code
    NativeRenderingPlugin IOS
    ranch实现游戏服务器
    erlang游戏开发tcp
    Erlang 命令行监控工具
    rebar安装及创建项目
    erlang中如何调试程序
  • 原文地址:https://www.cnblogs.com/wujie123/p/5256168.html
Copyright © 2011-2022 走看看