通知传值 notification
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.textF = [[UITextField alloc] initWithFrame:CGRectMake(100, 100, 100, 40)];
self.textF.borderStyle = 2;
self.textF.backgroundColor = [UIColor redColor];
[self.view addSubview:self.textF];
self.textF.delegate = self;
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(notification:) name:@"notification" object:nil];
}
-(void)notification:(NSNotification *)notification
{
self.textF.text = notification.userInfo[@"name"];
NSLog(@"你好");
}
-(void)dealloc
{
[[NSNotificationCenter defaultCenter]removeObserver:self];
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
if ([self.textF isFirstResponder]) {
[self.textF resignFirstResponder];
FirstViewController *firstC = [[FirstViewController alloc] init];
firstC.str = self.textF.text;
[self presentViewController:firstC animated:YES completion:^{
}];
}
}
@implementation FirstViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor redColor];
self.myText = [[UITextField alloc] initWithFrame:CGRectMake(100, 100, 100, 40)];
self.myText.borderStyle = 2;
self.myText.backgroundColor = [UIColor redColor];
[self.view addSubview:self.myText];
self.myText.delegate = self;
self.myText.text = self.str;
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
if ([self.myText isFirstResponder]) {
[self.myText resignFirstResponder];
}
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
NSNotification *notification = [NSNotification notificationWithName:@"notification" object:nil userInfo:@{@"name":self.myText.text}];
[[NSNotificationCenter defaultCenter] postNotification:notification];
NSLog(@"%@",notification.userInfo[@"name"]);
[self dismissViewControllerAnimated:YES completion:^{
}];
return YES;
}
通知传值 notification的更多相关文章
- Android消息通知(notification)和PendingIntent传值
通知栏的自定义布局:转:http://blog.csdn.net/vipzjyno1/article/details/25248021 拓展 实现自定义的通知栏效果: 这里要用到RemoteViews ...
- Notification 通知传值
通知 是在跳转控制器之间常用的传值代理方式,除了代理模式,通知更方便.便捷,一个简单的Demo实现通知的跳转传值. 输入所要发送的信息 ,同时将label的值通过button方法调用传递, ...
- iOS 页面跳转传值,属性传值,代理传值,代码块传值,单例传值,通知传值
有时候我们在页面跳转的时候回传递相应的参数,如,你想把在第一个页面的文本框里的内容显示在第二个文本框中,或者你又想把第二个文本框中的内容改变之后到第一个页面的文本框中,所有,这个时候我们就要用到页面跳 ...
- iOS pop使用通知传值
iOS pop回父级页面,使用通知传值 输入所要发送的信息 ,同时将label的值通过button方法调用传递, - (IBAction)buttonClick:(id)sender { //添加 字 ...
- iOS通知传值的使用
通知 是在跳转控制器之间常用的传值代理方式,除了代理模式,通知更方便.便捷,一个简单的Demo实现通知的跳转传值. 输入所要发送的信息 ,同时将label的值通过button方法调用传递, - (IB ...
- 通知传值(NSNotificationCenter)
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvenVveW91MTMxNA==/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...
- iOS传值之通知传值(三)
输入所要发送的信息 ,同时将label的值通过button方法调用传递, - (IBAction)buttonClick:(id)sender { //添加 字典,将label的值通过key值设置传递 ...
- iOS多视图传值方式之通知传值(NSNotification;NSNotificationCenter)
iOS传值方式之5:通知传值 第一需要发布的消息,再创建NSNotification通知对象,然后通过NSNotificationCenter通知中心发布消息(NSNotificationCenter ...
- HTML5开启浏览器桌面通知 Web Notification
说明: 1.Chrome要求必须https才可以开启浏览器通知 2.显示图片在本服务器,不支持跨越 3.自定义声音Chrome不播放,Firefox正常播放 代码如下: <!-- /** * @ ...
随机推荐
- L2-010. 排座位
L2-010. 排座位 题目链接:https://www.patest.cn/contests/gplt/L2-010 并查集 相关题目:L2-007. 家庭房产,L3-003. 社交集群 下午打的时 ...
- c socket(续)
存在两种字节顺序:NBO与HBO 网络字节顺序NBO(Network Byte Order):按从高到低的顺序存储,在网络上使用统一的网络字节顺序,可以避免兼容性问题. 主机字节顺序(HBO,Host ...
- OSCache 使用
引入OSCache的jar包 package com.sun.utils; import java.util.Date; import com.opensymphony.oscache.base.Ne ...
- javascript的insertBefore、insertAfter和appendChild简单介绍
target.insertBefore(newChild,existingChild)参数说明:1.target:被添加节点和现有节点的父节点.2.newChild:将要被插入的节点.3.exis ...
- 3.通过js代码设置css样式
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Java "==" 和 "equals" 和 "" 问题
//equals()方法出现的问题 String a="testd"; String b="testd"; String c=new String(" ...
- Chapter 16_3 多重继承
在Lua中进行面向对象编程时有几种方法,上一小结介绍了一种使用__index元方法的做法. 下面要介绍另一种方法,可以在Lua中实现多继承. 关键一点,在于用函数作为__index元字段. 多重继承意 ...
- 找斐波那契数列中的第N个数——递归与函数自调用算法
题目描述 Description 用递归的方法求斐波那契数列中的第N个数 输入输出格式 Input/output 输入格式:一行,一个正整数n输出格式: 一行,一个数,表示斐波那契数列中的第N个数 ...
- Openjudge-计算概论(A)-奇数求和
描述: 计算非负整数 m 到 n(包括m 和 n )之间的所有奇数的和,其中,m 不大于 n,且n 不大于300.例如 m=3, n=12, 其和则为:3+5+7+9+11=35. 输入两个数 m 和 ...
- ELK 基本搭建
ELK是一套日志分析系统: 开发人员不能登录线上服务器查看详细日志各个系统都有日志,日志数据分散难以查找日志数据量大,查询速度慢,或者数据不够实时一个调用会设计多个系统,难以在这些系统的日志中快速定位 ...