@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. table 中的td 字段超长,超过部分用....表示

    #contentTable{ table-layout:fixed;}.contentShort{ text-overflow: ellipsis; overflow: hidden; white-s ...

  2. Java 反射 设计模式 动态代理机制详解 [ 转载 ]

    Java 反射 设计模式 动态代理机制详解 [ 转载 ] @author 亦山 原文链接:http://blog.csdn.net/luanlouis/article/details/24589193 ...

  3. Understanding continuations

    原文地址http://fsharpforfunandprofit.com/posts/computation-expressions-continuations/ 上一篇中我们看到复杂代码是如何通过使 ...

  4. openwrt设置语言的过程

    设置语言的流程一.关联的配置文件/etc/config/luci查看配置文件内容如下:root@hbg:/# cat /etc/config/luci config core 'main'       ...

  5. From windows live writer

    天线数据长度: 4*14*9664*4 = 2164736 信道估计长度: 614400 均衡: 12*1200*4 = 57600

  6. Openjudge-计算概论(A)-过滤多余的空格

    描述: 一个句子中也许有多个连续空格,过滤掉多余的空格,只留下一个空格. 输入一行,一个字符串(长度不超过200),句子的头和尾都没有空格.输出过滤之后的句子. 样例输入 Hello world.Th ...

  7. nmon性能统计工具使用-初认识

    1.概述 监控,在检查系统问题或优化系统性能工作上是一个不可缺少的部分.通过操作系统监控工具监视操作系统资源的使用情况,间接地反映了各服务器程序的运行情况.根据运行结果分析可以帮助我们快速定位系统问题 ...

  8. 杭电1002 Etaoin Shrdlu

    Problem Description The relative frequency of characters in natural language texts is very important ...

  9. SQL函数学习(三):convert()函数

    格式:CONVERT(data_type,expression[,style])说明:此样式一般在时间类型(datetime,smalldatetime)与字符串类型(nchar,nvarchar,c ...

  10. stm32时钟配置总结

    stm32时钟配置时钟源: 1,HSE(高速外部时钟)即常见的外接8M晶振方案: 2,HSI(高速内部时钟) 即8M内部振荡时钟方案: 3,LSE(低速外部时钟)即常见的32.768Khz晶振方案: ...