通知传值 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正常播放 代码如下: <!-- /** * @ ...
随机推荐
- jquery 里 $(this)的用法
当遇到循环table时,查看其中的td.tr属性和值会有一点的麻烦.此时就必须使用$(this)来解决这一类的问题了. 1.直接使用 2.间接使用 <table> <?php for ...
- 2016年团体程序设计天梯赛-决赛 L1-2. I Love GPLT(5)
这道超级简单的题目没有任何输入. 你只需要把这句很重要的话 —— “I Love GPLT”——竖着输出就可以了. 所谓“竖着输出”,是指每个字符占一行(包括空格),即每行只能有1个字符和回车. #i ...
- javascript基础(三)运算
原文http://pij.robinqu.me/ 递增递减操作符(包括前置和后置).一元正负符号操作符 这些操作符适用于任何数据类型的值,针对不同类型的值,该操作符遵循以下规则(经过对比发现,其规则与 ...
- jquery makearray()使用
makearray(),转换一个类似数组的对象成为真正的JavaScript数组.首先看看jquery中array的定义 makeArray: function( arr, results ) { v ...
- react中文API解读二(教程)
记下自己的react学习之路 ,官方文档写的很详尽,学起来应该比较简单 官方文档地址:react.http://reactjs.cn/react/docs/getting-started.html 2 ...
- 一个简单的Servlet工具
以前老师在项目中用过一个Sevlet的工具,就是在请求Servlet的时候带一个参数,该参数决定要执行Servlet中的方法, public class ServletUtils extends Ht ...
- HDU 2955 Robberies(01背包)
Robberies Problem Description The aspiring Roy the Robber has seen a lot of American movies, and kno ...
- java 单元测试
---恢复内容开始--- 1/引入包:junit-4.11.jar|hamcrest-core-1.3(alilib里有) 2/与src同级建立一个文件夹,名为test,右击,Mark Directo ...
- eclipse和tomcat整合之后每次发布server.xml被修改(转)
eclipse每次发布,server.xml和context.xml总是被还原 直接找到eclispse工程下的server工程,把里面的相应的server.xml和context.xml修改了即可, ...
- Objective-C 2.0属性(Property)介绍
通常在声明一些成员变量时会看到如下声明方式: @property (参数1,参数2) 类型 名字: 这里我们主要分析在括号中放入的参数,主要有以下三种: setter/getter方法(assign/ ...