iOS利用通知逆传值
直接创建两个控制器,点击跳转第二个界面,然后点击按钮进行传值
#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利用通知逆传值的更多相关文章
- iOS利用通知(NSNotification)进行传值
通知 是在跳转控制器之间常用的传值代理方式,除了代理模式,通知更方便.便捷,一个简单的Demo实现通知的跳转传值. iOS通知传值的使用 输入所要发送的信息 ,同时将label的值通过button方法 ...
- [iOS]利用通知实现监听系统键盘
// // ViewController.m // text // // Created by 李东旭 on 16/1/22. // Copyright © 2016年 李东旭. All rights ...
- iOS学习——页面的传值方式
一.简述 在iOS开发过程中,页面跳转时在页面之间进行数据传递是很常见的事情,我们称这个过程为页面传值.页面跳转过程中,从主页面跳转到子页面的数据传递称之为正向传值:反之,从子页面返回主页面时的数据传 ...
- iOS之 利用通知(NSNotificationCenter)获取键盘的高度,以及显示和隐藏键盘时修改界面的注意事项
我们在开发中会遇到这样的情况:调用键盘时需要界面有一个调整,避免键盘遮掩输入框. 但实现时你会发现,在不同的手机上键盘的高度是不同的.这里列举一下: //获取键盘的高度 /* iphone 6: 中文 ...
- iOS中通知传值
NSNotification 通知中心传值,可以跨越多个页面传值, 一般也是从后面的页面传给前面的页面. 思路: 第三个界面的值传给第一个界面. 1. 在第一个界面建立一个通知中心, 通过通知中心 ...
- IOS 页面之间的传值(主讲delegate)
IOS的Delegate,通俗一点说就是页面之间的传值. 总结一下现在知道的IOS页面之间传值的方式有三种 1.使用NSNotification发送通知的传值 主要是通过NSNotificationC ...
- ios常见的页面传值方式
iOS页面间的传值细分有很多种,基本的传值方式有三种:委托Delegate传值.通知NSNotification传值.Block传值,其他在项目中可能会遇到的还有:UserDefault或文件方式传值 ...
- iOS - Notification 通知
1.Notification 通知中心实际上是在程序内部提供了消息广播的一种机制,它允许我们在低程度耦合的情况下,满足控制器与一个任意的对象进行通信的目的.每一个 iOS 程序(即每一个进程)都有一个 ...
- IOS中通知中心(NSNotificationCenter)
摘要 NSNotification是IOS中一个调度消息通知的类,采用单例模式设计,在程序中实现传值.回调等地方应用很广. IOS中通知中心NSNotificationCenter应用总结 一.了 ...
随机推荐
- Android 使用Socket进行通信(Android)
一.服务器程序 服务器程序需要在PC上运行,该程序比较的简单,因此不需要建立Android项目,直接定义一个JAVA类,并且运行该类即可.它仅仅建立ServerSocket监听,并使用Socket获取 ...
- DER input, Integer tag error的异常处理
1.首先我向大家介绍一下我做的东西,发生这个异常的情况. 我做的是一个电签的系统,在调用某公司的API生成证书,然后与安证通进行同步证书的任务. 2.问题具体的异常 具体异常如下: 2016/08/2 ...
- Spring常见问题-通配符的匹配很全面, 但无法找到元素 'aop:aspectj-autoproxy' 的声明
- Could not find a getter for id in class 的异常
检查.hbm.xml里边的id是否大小写一致
- BufferedReader与Scanner的区别
在Java中,我们都知道Java的标准输入串是System.in.但是我们却很少在Java中看到谁使用它,这是因为我们平时输入的都是一个字符串或者是一个数字等等.而System.in提供的read方法 ...
- Uploadify/uploadifive上传(中文文档)
Uploadify是一款基于JQuery的优秀的文件/图片上传的插件,有基于Flash和HTML5两种版本. Uploadify/uploadifive主要特点有: 1. 多文件上传 2. 个性化设 ...
- C++11基于范围的for循环
C++11包含一种新的 for 循环,称为基于范围的 for 循环,可以简化对数组元素的遍历.格式如下: for(Type VarName : Array){ //每个元素的值会依次赋给 VarNam ...
- spring-cloud-event-sourcing-example-master 运行效果及说明
1.微服务架构下电商示例,部署成功!监控等技术细节未深入研究. 简单介绍: 配置服务(config-service ),端口8888,健康检查 xx:8888/hea ...
- apt-get update : pulic key error
apt-get update 出现 这种错误 Reading package lists... Done W: There is no public key available for the fo ...
- eclipse中搭建svn开发管理环境
1.准备好资源 subversive,若是离线安装,已为大家准备好:http://pan.baidu.com/s/1hrbXH9y(本人喜欢离线安装,在线安装就不在此说了,其实只要一种方法简单的方法能 ...