@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. iOS开发传感器相关

    手机里面内置了很多的传感器,例如:光传感器,湿度传感器,温度传感器,距离传感器等等 //开发传感器相关的东西必须使用真机 //在螺旋仪和加速计所有两种方式push和pull的方式,push的方式是时时 ...

  2. hdu2141AC代码分享

    #include <iostream> #include <algorithm> using namespace std; const int N = 505; /////// ...

  3. C#实现文件的压缩和解压

    这里主要解决文件夹包含文件夹的解压缩问题.1)下载SharpZipLib.dll,在http://www.icsharpcode.net/OpenSource/SharpZipLib/Download ...

  4. openwrt 更改 debug 等级(hostapd)

    https://wiki.openwrt.org/doc/devel/debugging 调试hostapd,其中hostapd的调试等级如下: # Levels (minimum value for ...

  5. HDU 2037 今年暑假不AC(贪心)

    今年暑假不AC Problem Description “今年暑假不AC?”“是的.”“那你干什么呢?”“看世界杯呀,笨蛋!”“@#$%^&*%...” 确实如此,世界杯来了,球迷的节日也来了 ...

  6. LeetCode OJ 55. Jump Game

    Given an array of non-negative integers, you are initially positioned at the first index of the arra ...

  7. 2016 ACM/ICPC Asia Regional Dalian ICPC大连现场赛

    讲道理我挺想去大连的…… 毕竟风景不错…… 而且这次能去北京也是靠大连网络赛这一场拉开的优势…… 一道补图最短路一道数学推论简直爽爆…… 当然 除了这一场 其他场都非常划水…… 上次看到别人的博客用这 ...

  8. 一个文字无缝滚动的jQuery插件

    直接上代码吧 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www. ...

  9. php类于对象

    类与对象是面向对象程序设计的一个基本概念,类就是指某一类东西,而对象就是某一个类的具体实例 比如:黑帮是一个类,那陈浩南就是这个类的一个对象 再比如:人是一个类,那张三就是这个类的一个具体的对象 ph ...

  10. Compile Time Assertion..

    The most seen assertion are during runtime, but this one is at compile time, to give the error more ...