通知---视图间数据的传递:标签显示输入的内容【多个视图中】
2017-04-27 08:14
441 查看
RootViewController.m
ModalViewController.m
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { //注冊通知 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(recieveData:) name:BackNotification object:nil]; } return self; } - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor greenColor]; //创建显示文字的label UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50, 100, 200, 40)]; label.tag = 102; label.backgroundColor = [UIColor grayColor]; [self.view addSubview:label]; [label release]; //加入按钮 UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; button.frame = CGRectMake(20, 20, 90, 60); [button setTitle:@"打开模态" forState:UIControlStateNormal]; [button addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:button]; } - (void)recieveData:(NSNotification *)notification { UILabel *label = (UILabel *)[self.view viewWithTag:102]; NSString *text = [notification.userInfo objectForKey:@"text"]; label.text = text; } - (void)buttonAction { ModalViewController *modalCtrl = [[[ModalViewController alloc] init] autorelease]; modalCtrl.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; [self presentViewController:modalCtrl animated:YES completion:NULL]; }
ModalViewController.m
#define BackNotification @"BackNotification" @interface ModalViewController () @end @implementation ModalViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor redColor]; //加入按钮 UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; button.frame = CGRectMake(20, 20, 90, 60); [button setTitle:@"关闭模态" forState:UIControlStateNormal]; [button addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:button]; //创建输入框 UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(50, 100, 200, 40)]; textField.tag = 101; textField.borderStyle = UITextBorderStyleRoundedRect; [self.view addSubview:textField]; [textField release]; } - (void)buttonAction { UITextField *field = (UITextField *)[self.view viewWithTag:101]; NSString *text = field.text; NSDictionary *dic = @{@"text":text}; //发送通知 [[NSNotificationCenter defaultCenter] postNotificationName:BackNotification object:self userInfo:dic]; [self dismissViewControllerAnimated:YES completion:NULL]; }
相关文章推荐
- 通知---视图间数据的传递:标签显示输入的内容【多个视图中】
- KVO---视图间数据的传递:标签显示输入的内容【多个视图中】
- 代理---视图间数据的传递:标签显示输入的内容【多个视图中】
- KVO---视图间数据的传递:标签显示输入的内容【多个视图中】
- 单例---视图间数据的传递:标签显示输入的内容【多个视图中】
- 代理---视图间数据的传递:标签显示输入的内容【多个视图中】
- 单例---视图间数据的传递:标签显示输入的内容【多个视图中】
- 标签显示输入的内容【同一个视图中】
- 模拟邮箱输入邮箱地址、收藏标签。input框输入内容后回车,内容显示成小方块并带删除按钮。
- Java后台去除前台传递数据中的页面标签(HTML,Javascript,Style),获取文本内容!
- AngularJS,实现输入框失焦添加内容到最前,当数据重复删除原来并显示在数组最前
- 一步步学习SPD2010--第五章节--处理数据视图(5)--显示和隐藏内容
- iframe标签引用显示为空,ie下 【此内容不能显示在一个框架中, 为了帮助保护在此网站中输入的信息的安全……】
- HTML,angularJS表格内容排序,点击删除,删除当前,输入内容显示包含内容的数据
- 一例knockout with绑定,异步调用数据为null导致的绑定div标签内容不能显示的解决
- EF5+MVC4系列(7) 后台SelectListItem传值给前台显示Select下拉框;后台Action接收浏览器传值的4种方式; 后台Action向前台View视图传递数据的四种方式(ViewDate,TempDate,ViewBag,Model (实际是ViewDate.Model传值))
- iOS:切换视图时,反向传递数据方法一:通知
- 在Action中查询出SQL SERVER表的数据,返回一个list。怎么在JSP页面中使用Struts标签,显示出表中的内容?(转)
- 页面显示内容按照输入时换行显示标签
- MFC编辑框输入内容与显示内容转为16进制数据——更正版