UIViewController 正向,反向传值
来源:互联网 发布:域名不支持生成短网址 编辑:程序博客网 时间:2024/05/17 23:48
正向传值,通过属性来传值,反向传值通过协议代理。
#import <UIKit/UIKit.h>#import "SecondViewController.h"@interface RootViewController : UIViewController <SendValue>@end#import "RootViewController.h"#import "SecondViewController.h"@interface RootViewController ()@end@implementation RootViewController- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{ self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self;}- (void)viewDidLoad{ [super viewDidLoad];// Do any additional setup after loading the view. }- (void)didReceiveMemoryWarning{ [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}- (void)viewWillAppear:(BOOL)animated{ if (self.navigationController.toolbarHidden){ self.navigationController.toolbarHidden = NO; }}- (void)loadView{ [super loadView]; UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:nil]; UIBarButtonItem *item2 = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:self action:nil]; UIBarButtonItem *space = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil]; NSArray *items = [NSArray arrayWithObjects:space, item, space, item2, space, nil]; [item release]; [item2 release]; [space release]; self.toolbarItems = items; [self.view setBackgroundColor:[UIColor purpleColor]]; self.navigationItem.title = @"whwh"; //正向,反向传值 UIButton *button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [button1 setFrame:CGRectMake(100, 100, 80, 40)]; [button1 setTitle:@"push" forState:UIControlStateNormal]; [self.view addSubview:button1]; [button1 addTarget:self action:@selector(pushNav:) forControlEvents:UIControlEventTouchUpInside];}- (void)pushNav:(id)sender{ SecondViewController *sec = [[SecondViewController alloc]init]; sec.delegate = self; self.navigationController.toolbarHidden = YES; sec.modalTransitionStyle = UIModalTransitionStyleCoverVertical; [self.navigationController pushViewController:sec animated:YES]; [sec release];}#pragma mark sendValueDelegate- (void)sendBtnTitle:(NSString *)title{ self.navigationItem.title = title;}@end#import <UIKit/UIKit.h>@protocol SendValue <NSObject>- (void)sendBtnTitle:(NSString *)title;@end@interface SecondViewController : UIViewController@property (nonatomic, assign) id<SendValue> delegate;@property (nonatomic, copy) NSString *currentTitle;@end#import "SecondViewController.h"@interface SecondViewController ()@end@implementation SecondViewController@synthesize delegate = _delegate;@synthesize currentTitle = _currentTitle;- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{ self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self;}- (void)viewDidLoad{ [super viewDidLoad];// Do any additional setup after loading the view.}- (void)didReceiveMemoryWarning{ [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}- (void)loadView{ [super loadView]; //正向,反向传值 for (int i = 0; i < 3; i ++){ UIButton *button3 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [button3 setFrame:CGRectMake(100, 200 + i * 50, 80, 40)]; [button3 setTitle:[NSString stringWithFormat:@"button %i", i] forState:UIControlStateNormal]; [button3 addTarget:self action:@selector(onclick:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:button3]; }}- (void)onclick:(UIButton *)btn{ NSString *title = btn.currentTitle; if ([_delegate respondsToSelector:@selector(sendBtnTitle:)]){ [_delegate sendBtnTitle:title]; } [self.navigationController popViewControllerAnimated:YES];}@end
- UIViewController 正向,反向传值
- 正向反向传值
- ios UIViewController 反向传值
- android的正向传值与反向传值
- Block在UITableViewcell中的正向和反向传值
- cocos2dx 场景间正向反向传
- iOS开发 UI 正向传值 反向传值,Block传值
- Swift 正向传值以及利用闭包(closure)实现反向传值(七)
- 界面之间2种正向 6种反向传值方式
- 零基础ios开发(八 正向和反向传值)
- 反向提问,正向做人
- 正向代理 反向代理
- 正向代理 反向代理
- 正向代理,反向代理
- DNS反向正向查询
- 正向代理 反向代理
- 正向代理、反向代理
- 反向代理,正向代理
- 编程与编程思想的区别
- Oracle 中oci 关于null 的处理方法
- C基础学习(三)
- 模拟AndroidPN Client(1)——AndroidPN源码简析
- Git分支管理策略
- UIViewController 正向,反向传值
- JSP 最佳实践: 用 jsp:include 控制动态内容
- 算法笔记
- Redis VS memcached
- 用Java向数据库中插入大量数据时的优化
- C++ reinterpret_cast,const_cast等 显式类型转换总结
- Windows下GIT的安装与配置
- 模拟AndroidPN Client(2)——XmppManager简析和模拟客户端
- 经典SQL面试题