@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的更多相关文章

  1. Android消息通知(notification)和PendingIntent传值

    通知栏的自定义布局:转:http://blog.csdn.net/vipzjyno1/article/details/25248021 拓展 实现自定义的通知栏效果: 这里要用到RemoteViews ...

  2. Notification 通知传值

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

  3. iOS 页面跳转传值,属性传值,代理传值,代码块传值,单例传值,通知传值

    有时候我们在页面跳转的时候回传递相应的参数,如,你想把在第一个页面的文本框里的内容显示在第二个文本框中,或者你又想把第二个文本框中的内容改变之后到第一个页面的文本框中,所有,这个时候我们就要用到页面跳 ...

  4. iOS pop使用通知传值

    iOS pop回父级页面,使用通知传值 输入所要发送的信息 ,同时将label的值通过button方法调用传递, - (IBAction)buttonClick:(id)sender { //添加 字 ...

  5. iOS通知传值的使用

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

  6. 通知传值(NSNotificationCenter)

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvenVveW91MTMxNA==/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...

  7. iOS传值之通知传值(三)

    输入所要发送的信息 ,同时将label的值通过button方法调用传递, - (IBAction)buttonClick:(id)sender { //添加 字典,将label的值通过key值设置传递 ...

  8. iOS多视图传值方式之通知传值(NSNotification;NSNotificationCenter)

    iOS传值方式之5:通知传值 第一需要发布的消息,再创建NSNotification通知对象,然后通过NSNotificationCenter通知中心发布消息(NSNotificationCenter ...

  9. HTML5开启浏览器桌面通知 Web Notification

    说明: 1.Chrome要求必须https才可以开启浏览器通知 2.显示图片在本服务器,不支持跨越 3.自定义声音Chrome不播放,Firefox正常播放 代码如下: <!-- /** * @ ...

随机推荐

  1. SLF4J 教程

    转自:SLF4J 教程 一.介绍:简单日记门面(simple logging Facade for java)SLF4J是为各种loging APIs提供一个简单统一的接口,从而使得最终用户能够在部署 ...

  2. html中的a标签特例讲解

    将自己的博客写成了一个大杂烩了,遇见啥问题就写啥问题.但是当看见自己网页的成品就特别的开心. 还记得看见过的一个故事,说是收费的东西好还是免费的东西好,有一个答案是最让我记忆深刻的.回复的一个答案是: ...

  3. MySQL Replicationation基础

    摘要 一.MySQL Replication 介绍MySQL Replication的基本概念,摘自于Mysql官网 二.Replication Configuration 2.1 Basic Ste ...

  4. 有关下行HARQ的一切

    1. 对于下行HARQ,有几种类型的下行传输需要UE反馈ACK/NACK 动态调度的下行传输:UE收到一个使用C-RNTI或TC-RNTI(对应随机接入过程中的Msg4)加扰的PDCCH和PDSCH, ...

  5. 阿里云 镜像 源 debian

    /etc/apt/sources.list deb http://mirrors.aliyun.com/debian wheezy main contrib non-freedeb-src http: ...

  6. MVC5的控制器,使用HttpPost方式时,接收的参数为null的原因

    1.问题现象 POST提交时,控制的Action接收到的参数为null, 但Request.Form.Request.Params等集合其实是包含提交的所有数据的 .如下截图: 2.该问题很诡异,重新 ...

  7. Chapter 16_2 继承

    类也是对象,所有它们也可以从其他类获得方法.这就是“继承”,可以在Lua中表示: Account = { balance = } function Account:new(o) o = o or {} ...

  8. 关于ios 程序加载百度地图lib,出现链接错误:找不到符号 (null): _OBJC_CLASS_$_BMKMapManager的解决办法

    报告的错误信息 ld: warning: ignoring file /Users/5012/Documents/sphuang/IOS_project/baidu_map/ShareLocation ...

  9. ACE_Message_Block消息数据类

    ACE_Message_Block ACE_Message_Block用于构建"固定"和"可变"长度的消息.ACE_Message_Block可以将多条消息连接 ...

  10. xxx app 项目问题解决一览

    前话:作为人生旅途中的小记录 不同账号玩法限制       解决 <vn_rule>x</vn_rule> 6.调整下注筹码 **** 解决 不同账号的玩法限制    **** ...