• StoryBoard 页面传值


    如图新建一个viewController和DetailViewController

    VC 和DetailVC 联线的Idetnifier 设置为:GoDetailVC

    ViewController主要代码
    - (IBAction)signInButtonTouched:(id)sender { [self performSegueWithIdentifier:@"GoDetailVC" sender:self]; } #pragma mark - prepare segue // A页面传值到B页面 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { [super prepareForSegue:segue sender:sender]; if ([segue.identifier isEqualToString:@"GoDetailVC"]) { DetailViewController *detailVC = segue.destinationViewController; detailVC.passValue = self.usernameTextField.text; } } // B页面传值到A页面 -(IBAction)done:(UIStoryboardSegue *)segue{ if ([segue.sourceViewController isKindOfClass:[DetailViewController class]]) { DetailViewController * svc = (DetailViewController *)segue.sourceViewController; self.passwordTextField.text = svc.textField.text; } }

    在StoryBoard中 DetailViewController的Done按钮 Action关联到 viewController的done方法 如图

    1.在VC页面中第一个textField中输入值 点击 Sing in 按钮就会把值传到DetailViewController 的textField中显示出来。

    2.在DetailViewController textField中修改值 点击Done 按钮就会把值回传到ViewController中

    如果 是Present 方式要怎么传值勒。如图

    用如下代码肯定传值行不通
    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { [super prepareForSegue:segue sender:sender]; if ([segue.identifier isEqualToString:@"GoDetailVC"]) { DetailViewController *detailVC = segue.destinationViewController; // 因为这取出来的是NavigationController 不是DetailViewController
    detailVC.passValue = self.usernameTextField.text; 
    }
    }

    所以修改为如下:
    // A页面传值到B页面
    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    {
        [super prepareForSegue:segue sender:sender];
        if([[segue identifier] isEqualToString:@"GoDetailVC"])
        {
            NSArray *viewControllerArray = [segue.destinationViewController viewControllers];
            DetailViewController *detailVC = [viewControllerArray objectAtIndex:0];
            detailVC.passValue = self.usernameTextField.text;
        }
    }

     

  • 相关阅读:
    oracle 中和mysql的group_concat有同样作用的写法
    sql find_in_set在oracle下的解决方案
    Django项目部署:使用uwsgi和nginx的方式
    virtualenvwrapper.sh报错: There was a problem running the initialization hooks.解决
    html中footer如何一直保持在页底
    mysqldump导出备份数据库报Table ‘performance_schema.session_variables‘ doesn‘t exist
    django-ckeditor添加代码功能(codesnippet)
    Django_外键查询和反查询
    python面向对象编程(OOP)
    Django模型中字段属性choice的使用
  • 原文地址:https://www.cnblogs.com/joesen/p/4585354.html
Copyright © 2020-2023  润新知