iOS 传值
来源:互联网 发布:域名跳转服务 编辑:程序博客网 时间:2024/06/03 19:21
首页页面
下一页页面
传值后首页页面
通知传值
- (void)viewDidLoad { [super viewDidLoad]; // 注册监听者 // name 的值要和发送通知页面的name值相同,用来区分哪一个通知 // object 的值为nil时,代表监听任何对象发送的通知,下文中用的是object:obj1 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeValue:) name:@"changeValue" object:nil];}- (void)changeValue:(NSNotification *)notifi{ // 可以传多值 if ([notifi.object isEqualToString:@"obj1"]) { NSString *str = [NSString stringWithFormat:@"%@--%@",[[notifi userInfo] objectForKey:@"value1"],[[notifi userInfo] objectForKey:@"value2"]]; _lbValue.text = str; }else { _lbValue.text = @"aaaaaa"; }}// 按钮点击事件- (IBAction)nextAction:(UIButton *)sender{ NextViewController *nextController = [[NextViewController alloc] init]; [self presentViewController:nextController animated:YES completion:nil];}
- (void)viewDidLoad { [super viewDidLoad];}// 按钮点击事件- (IBAction)finishAction:(UIButton *)sender{ // 发送通知 // userInfo 为附加属性,为字典类型 [[NSNotificationCenter defaultCenter] postNotificationName:@"changeValue" object:@"obj1" userInfo:@{@"value1":_tfText.text,@"value2":@"111111"}]; [self dismissViewControllerAnimated:YES completion:nil];}
代理传值
@interface ViewController () <ChangeValueDelegte>@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; }- (IBAction)nextAction:(id)sender{ NextViewController *nextController = [[NextViewController alloc] init]; // 遵守协议 nextController.delegate = self; [self presentViewController:nextController animated:YES completion:nil];}// 实现协议中的方法- (void)shoudChangeValue:(NSString *)paraStr{ _lbValue.text = paraStr;}
#import <UIKit/UIKit.h>// 声明一个协议@protocol ChangeValueDelegte <NSObject>- (void)shoudChangeValue:(NSString *)paraStr;@end@interface NextViewController : UIViewController@property (nonatomic,weak) IBOutlet UITextField *tfValue;// 注意delegate用weak修饰,为防止循环引用@property (nonatomic,weak) id<ChangeValueDelegte> delegate;@end- (void)viewDidLoad { [super viewDidLoad];}- (IBAction)finishAction:(id)sender{ // 让代理传值 [_delegate shoudChangeValue:_tfValue.text]; [self dismissViewControllerAnimated:YES completion:nil];}
block传值
- (void)viewDidLoad { [super viewDidLoad];}- (IBAction)nextAction:(id)sender{ NextViewController *nextController = [[NextViewController alloc] init]; // 实现block [nextController setChangeValue:^(NSString *param){ _lbValue.text = param; }]; [self presentViewController:nextController animated:YES completion:nil];}
#import <UIKit/UIKit.h>// 声明一个blocktypedef void(^ShoudChangeValue)(NSString *paraStr);@interface NextViewController : UIViewController@property (nonatomic,weak) IBOutlet UITextField *tfValue;// block 用copy修饰@property (nonatomic,copy) ShoudChangeValue changeValue;@end- (void)viewDidLoad { [super viewDidLoad];}- (IBAction)finishAction:(id)sender{ // 调用block传值 _changeValue(_tfValue.text); [self dismissViewControllerAnimated:YES completion:nil];}
0 0
- ios 传值
- IOS 传值
- iOS 传值
- iOS 传值
- iOS传值(block传值)
- IOS传值:block传值
- ios block传值
- IOS Delegate传值
- IOS Block传值
- IOS传值-代码块传值
- IOS编程 之 传值
- iOS- UI界面-传值
- IOS 传值 总结
- ios block传值
- iOS UI11_BLOCK传值
- ios Segue传值
- ios Block传值
- iOS block传值
- 基于XMPP协议的Android IM研究
- jsp脚本、jsp声明、jsp输出表达式、javascript、jsp标签、struts2标签
- Matlab中各类函数用法
- java 汇总
- SDWebImage内部实现原理剖析
- iOS 传值
- Mysql 按年度、季度、月度、周、日统计查询的例子
- iOS 心得五 iOS7的适配(特别是单元格的动态适配)
- 去除字符串中的双引号
- Android之Monkey全参数
- 使用 Secure Shell Client工具操作linux常用命令打包到测试命令
- 基于OWIN的WEB API承载
- 基于.NET平台常用的框架整理
- android中颜色设置内容