zoukankan      html  css  js  c++  java
  • iOS开发—页面传值汇总

    情况1:A页面跳转到B页面

    方法1:在页面跳转的同时,将A页面的值带到B页面

    B页面的控制器中设置一个接收值的对象,并且设置一个显示值的textfield,设置outlet

    @property (nonatomic, copy) NSString *text;
    @property (weak, nonatomic) IBOutlet UITextField *textField2;
    

    在B页面的控制器中的viewDidLoad将A页面传过来的值显示到textField上

    - (void)viewDidLoad {
        [super viewDidLoad];
        self.textField2.text = self.text;
    }
    

    A页面的控制器中设置输入框以及跳转按钮

    @property (weak, nonatomic) IBOutlet UITextField *textField;
    - (IBAction)btnClicked:(id)sender;
    

    再给A页面的控制器中的按钮设置跳转事件

    - (IBAction)btnClicked:(id)sender {
        SecondViewController *nc = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"secondvc"];
        nc.text = self.textField.text;
        [self.navigationController pushViewController:nc animated:YES];
    }
    

    方法2:通过segue传值

     使用segue的performSegueWithIdentifier:sender:方法创建

    [self performSegueWithIdentifier:@"secondVC" sender:self];
    

    再通过- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender方法传值,将A页面的值带到B页面中去,在B页面的viewDidLoad方法中赋值

    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    {
        if([segue.identifier compare:@"secondVC"]==NO)
        {        id page2=segue.destinationViewController;
            [page2 setValue:self.textField.text forKey:@"value1"];
        }
    }

    情况2:A页面跳转到B页面,B页面再跳转回A页面

    方法:

    转自:http://www.cnblogs.com/JuneWang/p/3850859.html

  • 相关阅读:
    CopyOnWriteArrayList
    Gradle version 2.2 is required. Current version is 2.10
    install mysql on ubuntu
    A<T extends B> and A <? extends B>
    java event listeners and dispatcher
    git
    linux patch usage
    Codeforces Round #404 (Div. 2) C 二分查找
    dijkstra算法模板及其用法
    Sublime Text 3 快捷键精华版
  • 原文地址:https://www.cnblogs.com/saurik/p/4940106.html
Copyright © 2011-2022 走看看