(一)属性传值

(二)代理(委托)传值


代理传值
适用于 反向传值 (从后往前传)
1.1 创建协议 及协议方法 在反向传值的页面(SecondViewController)中
1.2 创建协议类型的属性 在SecondViewController中创建属性id<postValueDelegate> delegate
1.3 调用属性 即delegate
在SecondViewController页面中 对象传值的方法中调用
[self.delegate postValue:self.textName.text];
1.4 在第一页 即显示修改过信息的页面
遵循协议 实现协议方法 指定代理对象(即 在页面传值参数的方法中为代理赋值)
secondVc.delegate=self;

文件目录:

FirstViewController.h

#import <UIKit/UIKit.h>
#import "SecondViewController.h"
@interface FirstViewController : UIViewController<UITextFieldDelegate,postValue> @property(strong,nonatomic) UITextField *textName;
@property(strong,nonatomic) UIButton *nextbutton; @end

FirstViewController.m

#import "FirstViewController.h"

@interface FirstViewController ()

@end

@implementation FirstViewController

- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor=[UIColor redColor];
self.textName=[[UITextField alloc] initWithFrame:CGRectMake(, , ,)];
self.textName.borderStyle=UITextBorderStyleLine;
self.textName.delegate=self;
[self.view addSubview:self.textName]; self.nextbutton=[[UIButton alloc] initWithFrame:CGRectMake(, , , )];
[self.nextbutton setTitle:@"下一页" forState:UIControlStateNormal];
self.nextbutton.backgroundColor=[UIColor grayColor];
[self.nextbutton addTarget:self action:@selector(nextPage) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:self.nextbutton]; } -(BOOL)textFieldShouldReturn:(UITextField *)textField
{
if ([textField isFirstResponder]) {
[textField resignFirstResponder];
} return YES;
} -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
[self.textName resignFirstResponder];
} -(void)nextPage
{
SecondViewController *secondVc=[[SecondViewController alloc] init];
secondVc.str=self.textName.text;
secondVc.deletage=self;
[self presentViewController:secondVc animated:YES completion:nil];
} -(void)postValue:(NSString *)str
{
self.textName.text=str;
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end

SecondViewController.h

#import <UIKit/UIKit.h>

// 创建协议

@protocol postValue <NSObject>

-(void)postValue:(NSString *)str;

@end

@interface SecondViewController : UIViewController<UITextFieldDelegate>

@property(strong,nonatomic) UITextField *textInfo;
@property(strong,nonatomic) UIButton *backbutton;
@property(strong,nonatomic) NSString *str; @property(strong,nonatomic) id<postValue> deletage; @end

SecondViewController.m

#import "SecondViewController.h"

@interface SecondViewController ()

@end

@implementation SecondViewController

- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor=[UIColor colorWithRed:0.541 green:0.878 blue:0.831 alpha:1.000]; self.textInfo=[[UITextField alloc] initWithFrame:CGRectMake(, , , )];
self.textInfo.borderStyle=UITextBorderStyleLine;
self.textInfo.text=self.str;
self.textInfo.delegate=self; [self.view addSubview:self.textInfo]; self.backbutton=[[UIButton alloc] initWithFrame:CGRectMake(, , , )];
[self.backbutton setTitle:@"上一页" forState:UIControlStateNormal];
self.textInfo.text=self.str;
[self.backbutton addTarget:self action:@selector(backPage) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:self.backbutton]; } -(BOOL)textFieldShouldReturn:(UITextField *)textField
{
if ([textField isFirstResponder]) {
[textField resignFirstResponder];
} return YES;
} -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
[self.textInfo resignFirstResponder];
} -(void)backPage
{
if (self.deletage!=) {
[self.deletage postValue:self.textInfo.text];
} [self dismissViewControllerAnimated:YES completion:nil];
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end

AppDelegate.h

#import <UIKit/UIKit.h>
#import"FirstViewController.h"
@interface AppDelegate : UIResponder <UIApplicationDelegate> @property (strong, nonatomic) UIWindow *window; @end

AppDelegate.m

#import "AppDelegate.h"

@interface AppDelegate ()

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
FirstViewController *firstVc=[[FirstViewController alloc] init]; self.window.rootViewController=firstVc; return YES;
}
.......

@end

(三)代码块传值

(四)通知传值

(五)单例传值

iOS--页面间的代理传值(属性、代理(委托)、代码块、单例、通知)的更多相关文章

  1. iOS 页面间几种传值方式(属性,代理,block,单例,通知)

    第二个视图控制器如何获取第一个视图控制器的部分信息 例如 :第二个界面中的lable显示第一个界面textField中的文本 这就需要用到属性传值.block传值 那么第一个视图控制器如何获的第二个视 ...

  2. iOS 页面间传值 之 属性传值,代理传值

    手机 APP 运行,不同页面间传值是必不可少,传值的方式有很多(方法传值,属性传值,代理传值,单例传值) ,这里主要总结下属性传值和代理传值. 属性传值:属性传值是最简单,也是最常见的一种传值方式,但 ...

  3. iOS 页面间传值 之 单例传值 , block 传值

    ios 页面间传值有许多,前边已经分享过属性传值和代理传值,今天主要说一下单例传值和 block 传值 单例传值:单例模式一种常用的开发的模式,单例因为在整个程序中无论在何时初始化对象,获取到的都是同 ...

  4. iOS页面间传值的方式 (Delegate/NSNotification/Block/NSUserDefault/单例)

    iOS页面间传值的方式(Delegate/NSNotification/Block/NSUserDefault/单例)   iOS页面间传值的方式(NSUserDefault/Delegate/NSN ...

  5. iOS页面间传值的六种方式

    一般ios页面间的传值方式分为6种:1.属性传值:2.block:3.delegate:4.UserDefault:5.单例:6.通知. 0&1.block 先说我最常用的block吧,属性传 ...

  6. iOS页面间传值的五种方式总结(Delegate/NSNotification/Block/NSUserDefault/单例)

    iOS页面间传值的方式(Delegate/NSNotification/Block/NSUserDefault/单例) iOS页面间传值的方式(NSUserDefault/Delegate/NSNot ...

  7. iOS页面间传值的方式(Delegate/NSNotification/Block/NSUserDefault/单例)

    iOS页面间传值实现方法:1.通过设置属性,实现页面间传值:2.委托delegate方式:3.通知notification方式:4.block方式:5.UserDefault或者文件方式:6.单例模式 ...

  8. iOS页面间传值的方式(NSUserDefault/Delegate/NSNotification/Block/单例)

    iOS页面间传值的方式(NSUserDefault/Delegate/NSNotification/Block/单例) 实现了以下iOS页面间传值:1.委托delegate方式:2.通知notific ...

  9. 【转】iOS页面间传值的方式(Delegate/NSNotification/Block/NSUserDefault/单例)-- 不错

    原文网址:http://www.cnblogs.com/JuneWang/p/3850859.html iOS页面间传值的方式(NSUserDefault/Delegate/NSNotificatio ...

  10. ios页面间传递参数四种方式

    ios页面间传递参数四种方式 1.使用SharedApplication,定义一个变量来传递. 2.使用文件,或者NSUserdefault来传递 3.通过一个单例的class来传递 4.通过Dele ...

随机推荐

  1. http协议客户端向服务器端请求时一般需要发送的内容

    out.println("GET /shopping/index.html HTTP/1.1");//请求行 包括请求方式,文件路径, http协议版本(必写)请求头.... ou ...

  2. codeforces B. Friends and Presents(二分+容斥)

    题意:从1....v这些数中找到c1个数不能被x整除,c2个数不能被y整除! 并且这c1个数和这c2个数没有相同的!给定c1, c2, x, y, 求最小的v的值! 思路: 二分+容斥,二分找到v的值 ...

  3. 【转载】Grunt常用插件介绍

    项目名称 grunt-contrib v0.8.0 项目地址 https://github.com/gruntjs/grunt-contrib 项目介绍 此项目是对grunt常用插件的集合,刚接触gr ...

  4. ECMAScript 6中的数组操作方法

    本文介绍ECMAScript 6即将带给我们新的数组操作方法,以及在怎样在现有浏览器应用这些新的数组特性. Note: 我将使用交替使用构造器(constructor)和类(class)两个术语. 类 ...

  5. IIS 7完全攻略之日志记录配置(摘自网络)

    IIS 7完全攻略之日志记录配置 作者:泉之源 [IT168 专稿]除了 Windows 提供的日志记录功能外,IIS 7.0 还可以提供其他日志记录功能.例如,可以选择日志文件格式并指定要记录的请求 ...

  6. Android学习笔记之DocumentBuilder的使用....

    PS:当你的才华还撑不起你的野心时,那你需要静下心来学习..... 学习内容: 1.从服务器上获取XML文档... 2.解析XML文档中的内容...   XML文件想必大家都非常的熟悉,可扩展的标记语 ...

  7. Sprint第三个冲刺(第四天)

    一.Sprint介绍 任务进度: 二.Sprint周期 看板: 燃尽图:

  8. IntelliJ IDEA 的SVN配置与使用

    SVN 首先提一句,IDEA对各种的版本控制工具的支持是非常好的,点击3 打开系统设置界面,就可以看到他有专门的一栏 Version Control 里边是对各种版本控制工具的支持,其中我要用的SVN ...

  9. asp.net中绘制大数据量的可交互的图表

    在一个asp.net项目中要用到能绘制大数据量信息的图表,并且是可交互的(放大.缩小.导出.打印.实时数据),能够绘制多种图形. 为此进行了多方调查预研工作,预研过微软的MsChart图表组件.基于j ...

  10. 关于DOM树的常见增删操作

    //具体关于DOM的内容可参考我的另外一篇文章"文本对象模型(Document Object Model)". 案例要点:     1.创建并增加元素节点     2.判断是否存在 ...