IOS学习之——ViewController之间正向传值
来源:互联网 发布:2015最新癌症数据统计 编辑:程序博客网 时间:2024/06/01 07:24
下面定义两个页面,为了简单起见,就不添加Btton进行页面跳转,直接点击屏幕,触发
touchesBegan事件,进行页面跳转。
//// OneViewController.m// 双向传值//// Created by spare on 16/4/16.// Copyright © 2016年 spare. All rights reserved.//#import "OneViewController.h"#import "TwoViewController.h"@interface OneViewController ()@property (weak, nonatomic) IBOutlet UITextField *textField1;@end@implementation OneViewController//点击屏幕任意位置,进入页面2-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ //初始化将要进入的页面 TwoViewController *vc2=[[TwoViewController alloc]init]; //通过页面2定义的Content属性,将值传给页面2 vc2.content=self.textField1.text; [self presentViewController:vc2 animated:YES completion:nil]; }- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view from its nib.}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}/*#pragma mark - Navigation// In a storyboard-based application, you will often want to do a little preparation before navigation- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller.}*/@end
#import <UIKit/UIKit.h>@interface TwoViewController : UIViewController
//页面1的对象不能直接访问页面2的textField属性//需要定义一个中间的变量值,将页面一的值保存在中间变量中@property(nonatomic,copy)NSString *content;@end
//// TwoViewController.m// 双向传值//// Created by spare on 16/4/16.// Copyright © 2016年 spare. All rights reserved.//#import "TwoViewController.h"@interface TwoViewController ()@property (weak, nonatomic) IBOutlet UITextField *textField2;@end@implementation TwoViewController- (void)viewDidLoad { [super viewDidLoad]; }//每次进入页面的时候,都去刷新获得的值-(void)viewWillAppear:(BOOL)animated{ //通过中间属性,传值给textField2; self.textField2.text=self.content;}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}/*#pragma mark - Navigation// In a storyboard-based application, you will often want to do a little preparation before navigation- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller.}*/@end
0 0
- IOS学习之——ViewController之间正向传值
- IOS学习之——ViewController之间双向传值(反向为代理模式)
- iOS两个viewController之间传值
- IOS 两个ViewController 之间传值
- iOS学习之——Present ViewController Modally
- ViewController之间传值
- iOS学习--ViewController之间的跳转
- IOS学习笔记——ViewController生命周期
- 【ios】2个viewController之间传值(segue方式)
- iOS 属性传值 Block传值 两个ViewController之间的
- iOS ViewController之间传值方法一(利用临时变量)
- iOS ViewController之间传值方法二(利用NSUserDefaults)
- iOS ViewController之间传值方法三(利用NSNotification)
- iOS ViewController之间传值方法四(利用Delegate)
- iOS ViewController之间传值方法五(使用block)
- iOS 不同界面(ViewController)之间传值
- iOS学习之——改变UITabBarController中当前显示的viewController
- IOS—两个ViewController间传值(逆向传值)
- hibernate对连接池的支持
- 一些linux的基本操作
- 在Android开发中使用Ant 一:环境的搭建及入门
- 从容器和Kubernetes技术看现代云计算的发展轨迹
- 合并两个排序的链表
- IOS学习之——ViewController之间正向传值
- 网络直播电视之M3U8解析篇 (下)
- 字符串计数(动态规划)
- java之Secure communication terminology
- 【DFS】HDU2181哈密顿绕行世界问题
- C++学习笔记之二 C++基础学习2
- adb操作命令详解及大全
- Apriori算法详解
- Leetcode题解 232. Implement Queue using Stacks