通知传值 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正常播放 代码如下: <!-- /** * @ ...
随机推荐
- discuz网站数据库迁移
你的discuz网站数据库迁移,或者修改过改密码后,还要以下相关配置文件修改,才能不会出现1045错误 以windows系统为例:首先登陆远程桌面,在运行中输入cmd,单开命令模式,再输入 net ...
- Counting Stars
Counting Stars 题目链接:http://acm.xidian.edu.cn/problem.php?id=1177 离线+一维树状数组 一眼扫过去:平面区间求和,1e6的数据范围,这要h ...
- Algorithm 算法
http://www.cnblogs.com/baiboy/category/723479.html 记下来,有空去看 随笔分类 - Algorithm [项目总结]自然语言处理在现实生活中运用 ...
- luci页面“save&apply”的实现分析
页面上配置的“保存&应用”功能的实现: 最终调用到/etc/config/ucitrack的配置文件. 例如配置无线时,对应ucitrack配置文件中的config network op ...
- JVM基础01-内存分配
一.什么是JVM Java作为主流编程语言: 它摆脱了硬件的束缚,一处编写,处处运行: 它提供了一种相对安全的内存管理和访问机制,避免了大部分的内存泄露和指针越界问题: 它实现了热点代码的检测和运行时 ...
- 工具类 util.img
/** * @description transform emotion image url between code * @author x.radish * @pa ...
- photoshop的页面制作练习1
- Hibernate框架--关联映射,一对多,多对多 inverse cascade
回顾Hibernate: 1. hibernate开发环境搭建 ----> 引入jar: hibernate.jar + required + jpa + 驱动包 ---> hiberna ...
- redis1--redis的介绍
(1)持久化数据库的缺点平常我们使用的关系型数据库有Mysql.Oracle以及SqlServer等,在开发的过程中,数据通常都是通过Web提供的数据库驱动来链接数据库进行增删改查.那么,我们日常使用 ...
- 关于Linode、Digitalocean、Vultr三款美国VPS服务商的用户体验
曾几何时,虽然我们在海外VPS服务商中也可以看到各种大大小小的商家,但是真正能让Linode这样高富帅有竞争力的还真不多,这不当初在Linode商家512MB内存方案卖20美元一个月的时候,还是有很多 ...