02-导航实例-storyboard实现
- 源代码下载链接:02-导航实例-storyboard实现.zip
38.5 KB -
// MJAboutViewController.h
- //
- // MJAboutViewController.h
- // 02-导航实例-storyboard实现
- //
- // Created by apple on 13-12-10.
- // Copyright (c) 2013年itcast. All rights reserved.
- //
- #import<UIKit/UIKit.h>
- @interfaceMJAboutViewController : UIViewController
- @end
-
// MJAboutViewController.m
Map - //
- // MJAboutViewController.m
- // 02-导航实例-storyboard实现
- //
- // Created by apple on 13-12-10.
- // Copyright (c) 2013年itcast. All rights reserved.
- //
- #import"MJAboutViewController.h"
- @interfaceMJAboutViewController ()
- @end
- @implementationMJAboutViewController
- - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
- {
- self= [superinitWithNibName:nibNameOrNil bundle:nibBundleOrNil];
- if(self) {
- // Custom initialization
- }
- returnself;
- }
- - (void)viewDidLoad
- {
- [superviewDidLoad];
- // Do any additional setup after loading the view.
- }
- - (void)didReceiveMemoryWarning
- {
- [superdidReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- @end
-
// MJEditViewController.h
Map - //
- // MJEditViewController.h
- // 02-导航实例-storyboard实现
- //
- // Created by apple on 13-12-10.
- // Copyright (c) 2013年itcast. All rights reserved.
- //
- #import<UIKit/UIKit.h>
- @classMJEditViewController;
- @protocolMJEditViewControllerDelegate <NSObject>
- @optional
- - (void)editViewController:(MJEditViewController *)edit didSaveName:(NSString *)name;
- @end
- @interfaceMJEditViewController : UIViewController
- - (IBAction)save:(id)sender;
- @property(weak,nonatomic)IBOutletUITextField *nameField;
- @property(nonatomic,weak)id<MJEditViewControllerDelegate> delegate;
- @property(nonatomic,copy) NSString *name;
- @end
-
// MJEditViewController.m
Map - //
- // MJEditViewController.m
- // 02-导航实例-storyboard实现
- //
- // Created by apple on 13-12-10.
- // Copyright (c) 2013年itcast. All rights reserved.
- //
- #import"MJEditViewController.h"
- @interfaceMJEditViewController ()
- @end
- @implementationMJEditViewController
- - (void)viewDidLoad
- {
- [superviewDidLoad];
- _nameField.text = _name;
- }
- - (IBAction)save:(id)sender {
- if([_delegate respondsToSelector:@selector(editViewController:didSaveName:)]) {
- [_delegate editViewController:selfdidSaveName:_nameField.text];
- //出栈
- [self.navigationController popViewControllerAnimated:YES];
- }
- }
- @end
-
// MJHomeViewController.h
Map - //
- // MJHomeViewController.h
- // 02-导航实例-storyboard实现
- //
- // Created by apple on 13-12-10.
- // Copyright (c) 2013年itcast. All rights reserved.
- //
- #import<UIKit/UIKit.h>
- @interfaceMJHomeViewController : UIViewController
- @property(weak,nonatomic)IBOutletUILabel *nameLabel;
- @end
-
// MJHomeViewController.m
Map - //
- // MJHomeViewController.m
- // 02-导航实例-storyboard实现
- //
- // Created by apple on 13-12-10.
- // Copyright (c) 2013年itcast. All rights reserved.
- //
- #import"MJHomeViewController.h"
- #import"MJEditViewController.h"
- @interfaceMJHomeViewController () <MJEditViewControllerDelegate>
- @end
- @implementationMJHomeViewController
- - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
- {
- self= [superinitWithNibName:nibNameOrNil bundle:nibBundleOrNil];
- if(self) {
- // Custom initialization
- }
- returnself;
- }
- - (void)viewDidLoad
- {
- [superviewDidLoad];
- // Do any additional setup after loading the view.
- }
- #pragma mark在执行segue跳转之前会调用一次(自动调用)
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
- {
- // 1.取得终点控制器
- MJEditViewController *dest = segue.destinationViewController;
- // 2.设置编辑控制器的代理
- dest.delegate =self;
- // 3.传递姓名给编辑控制器
- dest.name = _nameLabel.text;
- // dest.nameField.text = _nameLabel.text;
- }
- #pragma mark MJEditViewController的代理方法
- - (void)editViewController:(MJEditViewController *)edit didSaveName:(NSString *)name
- {
- _nameLabel.text = name;
- }
- @end
-
// MJLoginViewController.h
Map - //
- // MJLoginViewController.h
- // 02-导航实例-storyboard实现
- //
- // Created by apple on 13-12-10.
- // Copyright (c) 2013年itcast. All rights reserved.
- //
- #import<UIKit/UIKit.h>
- @interfaceMJLoginViewController : UIViewController
- - (IBAction)login;
- @property(weak,nonatomic)IBOutletUITextField *qqField;
- @property(weak,nonatomic)IBOutletUITextField *pwdField;
- @end
-
// MJLoginViewController.m
Map - //
- // MJLoginViewController.m
- // 02-导航实例-storyboard实现
- //
- // Created by apple on 13-12-10.
- // Copyright (c) 2013年itcast. All rights reserved.
- //
- #import"MJLoginViewController.h"
- @interfaceMJLoginViewController ()
- @end
- @implementationMJLoginViewController
- - (void)viewDidLoad
- {
- [superviewDidLoad];
- // Do any additional setup after loading the view.
- }
- - (IBAction)login {
- if(_qqField.text.length ==0|| _pwdField.text.length ==0)return;
- //手动执行那根线(一根线就代表一个segue对象)
- [selfperformSegueWithIdentifier:@"login2home"sender:@"789"];
- }
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
- {
- NSLog(@"----------------%@", sender);
- }
- @end
作者:
出处:http://www.cnblogs.com/ChenYilong/(点击RSS订阅)
本文版权归作者和博客园共有,欢迎转载,
但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。