直接创建两个控制器,点击跳转第二个界面,然后点击按钮进行传值

#import "ViewController.h"

#import "TWOOViewController.h"

@interface ViewController ()

@property(nonatomic,weak)UILabel * label;

@end

@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

UIButton * nextBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 50, self.view.bounds.size.width, 50)];

nextBtn.backgroundColor = [UIColor redColor];

[nextBtn addTarget:self action:@selector(nextBtnClick:) forControlEvents:UIControlEventTouchUpInside];

[nextBtn setTitle:@"下一个界面" forState:UIControlStateNormal];

[self.view addSubview:nextBtn];

UILabel * labeltext = [[UILabel  alloc]initWithFrame:CGRectMake(0, 150, self.view.bounds.size.width, 50)];

labeltext.backgroundColor = [UIColor yellowColor];

labeltext.textColor = [UIColor greenColor];

[self.view addSubview:labeltext];

self.label = labeltext;

//创建通知

[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(nexttow:) name:@"nextBtnaa" object:nil];

}

-(void)nextBtnClick:(UIButton*)nextBtn{

TWOOViewController * two = [[TWOOViewController alloc]init];

[self presentViewController:two animated:YES completion:nil];

}

-(void)nexttow:(NSNotification*)nontification{

self.label.text = nontification.object;

}

第二个控制器

#import "TWOOViewController.h"

@interface TWOOViewController ()

@end

@implementation TWOOViewController

- (void)viewDidLoad {

[super viewDidLoad];

self.view.backgroundColor = [UIColor blueColor];

UIButton  * backBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 79, self.view.bounds.size.width, 50)];

[backBtn setTitle:@"回" forState:UIControlStateNormal];

[backBtn addTarget:self action:@selector(backBtnClick:) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:backBtn];

}

-(void)backBtnClick:(UIButton*)backBtn{

[[NSNotificationCenter defaultCenter]postNotificationName:@"nextBtnaa" object:@"逆传值"];

//隐藏本控制器

[self dismissViewControllerAnimated:YES completion:nil];

}

结果:

iOS利用通知逆传值的更多相关文章

  1. iOS利用通知(NSNotification)进行传值

    通知 是在跳转控制器之间常用的传值代理方式,除了代理模式,通知更方便.便捷,一个简单的Demo实现通知的跳转传值. iOS通知传值的使用 输入所要发送的信息 ,同时将label的值通过button方法 ...

  2. [iOS]利用通知实现监听系统键盘

    // // ViewController.m // text // // Created by 李东旭 on 16/1/22. // Copyright © 2016年 李东旭. All rights ...

  3. iOS学习——页面的传值方式

    一.简述 在iOS开发过程中,页面跳转时在页面之间进行数据传递是很常见的事情,我们称这个过程为页面传值.页面跳转过程中,从主页面跳转到子页面的数据传递称之为正向传值:反之,从子页面返回主页面时的数据传 ...

  4. iOS之 利用通知(NSNotificationCenter)获取键盘的高度,以及显示和隐藏键盘时修改界面的注意事项

    我们在开发中会遇到这样的情况:调用键盘时需要界面有一个调整,避免键盘遮掩输入框. 但实现时你会发现,在不同的手机上键盘的高度是不同的.这里列举一下: //获取键盘的高度 /* iphone 6: 中文 ...

  5. iOS中通知传值

    NSNotification 通知中心传值,可以跨越多个页面传值, 一般也是从后面的页面传给前面的页面.   思路: 第三个界面的值传给第一个界面. 1. 在第一个界面建立一个通知中心, 通过通知中心 ...

  6. IOS 页面之间的传值(主讲delegate)

    IOS的Delegate,通俗一点说就是页面之间的传值. 总结一下现在知道的IOS页面之间传值的方式有三种 1.使用NSNotification发送通知的传值 主要是通过NSNotificationC ...

  7. ios常见的页面传值方式

    iOS页面间的传值细分有很多种,基本的传值方式有三种:委托Delegate传值.通知NSNotification传值.Block传值,其他在项目中可能会遇到的还有:UserDefault或文件方式传值 ...

  8. iOS - Notification 通知

    1.Notification 通知中心实际上是在程序内部提供了消息广播的一种机制,它允许我们在低程度耦合的情况下,满足控制器与一个任意的对象进行通信的目的.每一个 iOS 程序(即每一个进程)都有一个 ...

  9. IOS中通知中心(NSNotificationCenter)

    摘要 NSNotification是IOS中一个调度消息通知的类,采用单例模式设计,在程序中实现传值.回调等地方应用很广.   IOS中通知中心NSNotificationCenter应用总结 一.了 ...

随机推荐

  1. val()失效

    在表单设置了disabled或者readonlye,那么val()方会失效,可以采用$().attr('value','')

  2. git常用指令

    <a>github的提交方式      git status     (1)git add .--------------------存储到本地       git add -u      ...

  3. 自动打开Accesibility Service 可以自动安装APP

    package com.venscor.helloworld;import java.io.BufferedReader;import java.io.IOException;import java. ...

  4. http的一些事

    查找资料将http中缓存相关的知识记录下 一般来说:Last-Modifed和Expires是一对,ETag和Cache-Control是一对 Last-Modified Client端跟Server ...

  5. spark读取hbase数据

    def main(args: Array[String]): Unit = { val hConf = HBaseConfiguration.create(); hConf.set("hba ...

  6. RDIFramework.NET-.NET快速信息化系统开发整合框架 【开发实例 EasyUI】之产品管理(MVC版)

    RDIFramework.NET—.NET快速开发整合框架 [开发实例]之产品管理(MVC版) 接上篇:RDIFramework.NET (.NET快速信息化系统开发整合框架) [开发实例]之产品管理 ...

  7. Pointcut is malformed: Pointcut is not well-formed: expecting 'identifier' at character position 0 ^

    错误提示: 解决方法:指定execution 在执行目标方法之前指定execution 例如: import org.aspectj.lang.annotation.Aspect; import or ...

  8. Hadoop: Hadoop Cluster配置文件

    Hadoop配置文件 Hadoop的配置文件: 只读的默认配置文件:core-default.xml, hdfs-default.xml, yarn-default.xml 和 mapred-defa ...

  9. Java线程新特征——Java并发库

    一.线程池   Sun在Java5中,对Java线程的类库做了大量的扩展,其中线程池就是Java5的新特征之一,除了线程池之外,还有很多多线程相关的内容,为多线程的编程带来了极大便利.为了编写高效稳定 ...

  10. Oracle11完全卸载

    1.停用oracle服务:进入计算机管理,在服务中,找到oracle开头的所有服务,右击选择停止 2.在开始菜单中,找到Universal Installer,运行Oracle Universal I ...