新浪微博 有道云笔记 麦库 EverNote Pocket Instapaper 更多

02-导航实例-storyboard实现

 

 

  1. 源代码下载链接:02-导航实例-storyboard实现.zip
    38.5 KB
  2. // MJAboutViewController.h

  3. //
  4. //  MJAboutViewController.h
  5. //  02-导航实例-storyboard实现
  6. //
  7. //  Created by apple on 13-12-10.
  8. //  Copyright (c) 2013itcast. All rights reserved.
  9. //

  10. #import<UIKit/UIKit.h>

  11. @interfaceMJAboutViewController : UIViewController

  12. @end
  13. // MJAboutViewController.m

    Map
  14. //
  15. //  MJAboutViewController.m
  16. //  02-导航实例-storyboard实现
  17. //
  18. //  Created by apple on 13-12-10.
  19. //  Copyright (c) 2013itcast. All rights reserved.
  20. //

  21. #import"MJAboutViewController.h"

  22. @interfaceMJAboutViewController ()

  23. @end

  24. @implementationMJAboutViewController

  25. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  26. {
  27.    self= [superinitWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  28.    if(self) {
  29.        // Custom initialization
  30.     }
  31.    returnself;
  32. }

  33. - (void)viewDidLoad
  34. {
  35.     [superviewDidLoad];
  36. // Do any additional setup after loading the view.
  37. }

  38. - (void)didReceiveMemoryWarning
  39. {
  40.     [superdidReceiveMemoryWarning];
  41.    // Dispose of any resources that can be recreated.
  42. }

  43. @end
  44. // MJEditViewController.h

    Map
  45. //
  46. //  MJEditViewController.h
  47. //  02-导航实例-storyboard实现
  48. //
  49. //  Created by apple on 13-12-10.
  50. //  Copyright (c) 2013itcast. All rights reserved.
  51. //

  52. #import<UIKit/UIKit.h>

  53. @classMJEditViewController;


  54. @protocolMJEditViewControllerDelegate <NSObject>

  55. @optional
  56. - (void)editViewController:(MJEditViewController *)edit didSaveName:(NSString *)name;

  57. @end

  58. @interfaceMJEditViewController : UIViewController
  59. - (IBAction)save:(id)sender;
  60. @property(weak,nonatomic)IBOutletUITextField *nameField;

  61. @property(nonatomic,weak)id<MJEditViewControllerDelegate> delegate;

  62. @property(nonatomic,copy) NSString *name;

  63. @end
  64. // MJEditViewController.m

    Map
  65. //
  66. //  MJEditViewController.m
  67. //  02-导航实例-storyboard实现
  68. //
  69. //  Created by apple on 13-12-10.
  70. //  Copyright (c) 2013itcast. All rights reserved.
  71. //

  72. #import"MJEditViewController.h"

  73. @interfaceMJEditViewController ()

  74. @end

  75. @implementationMJEditViewController

  76. - (void)viewDidLoad
  77. {
  78.     [superviewDidLoad];
  79.    
  80.     _nameField.text = _name;
  81. }

  82. - (IBAction)save:(id)sender {
  83.    if([_delegate respondsToSelector:@selector(editViewController:didSaveName:)]) {
  84.         [_delegate editViewController:selfdidSaveName:_nameField.text];
  85.        
  86.        
  87.        //出栈
  88.         [self.navigationController popViewControllerAnimated:YES];
  89.     }
  90. }
  91. @end
  92. // MJHomeViewController.h

    Map
  93. //
  94. //  MJHomeViewController.h
  95. //  02-导航实例-storyboard实现
  96. //
  97. //  Created by apple on 13-12-10.
  98. //  Copyright (c) 2013itcast. All rights reserved.
  99. //

  100. #import<UIKit/UIKit.h>

  101. @interfaceMJHomeViewController : UIViewController
  102. @property(weak,nonatomic)IBOutletUILabel *nameLabel;

  103. @end
  104. // MJHomeViewController.m

    Map
  105. //
  106. //  MJHomeViewController.m
  107. //  02-导航实例-storyboard实现
  108. //
  109. //  Created by apple on 13-12-10.
  110. //  Copyright (c) 2013itcast. All rights reserved.
  111. //

  112. #import"MJHomeViewController.h"
  113. #import"MJEditViewController.h"

  114. @interfaceMJHomeViewController () <MJEditViewControllerDelegate>

  115. @end

  116. @implementationMJHomeViewController

  117. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  118. {
  119.    self= [superinitWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  120.    if(self) {
  121.        // Custom initialization
  122.     }
  123.    returnself;
  124. }

  125. - (void)viewDidLoad
  126. {
  127.     [superviewDidLoad];
  128. // Do any additional setup after loading the view.
  129. }

  130. #pragma mark在执行segue跳转之前会调用一次(自动调用)
  131. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
  132. {
  133.    // 1.取得终点控制器
  134.     MJEditViewController *dest = segue.destinationViewController;
  135.    
  136.    // 2.设置编辑控制器的代理
  137.     dest.delegate =self;
  138.    
  139.    // 3.传递姓名给编辑控制器
  140.     dest.name = _nameLabel.text;
  141. //    dest.nameField.text = _nameLabel.text;
  142. }

  143. #pragma mark MJEditViewController的代理方法
  144. - (void)editViewController:(MJEditViewController *)edit didSaveName:(NSString *)name
  145. {
  146.     _nameLabel.text = name;
  147. }
  148. @end
  149. // MJLoginViewController.h

    Map
  150. //
  151. //  MJLoginViewController.h
  152. //  02-导航实例-storyboard实现
  153. //
  154. //  Created by apple on 13-12-10.
  155. //  Copyright (c) 2013itcast. All rights reserved.
  156. //

  157. #import<UIKit/UIKit.h>

  158. @interfaceMJLoginViewController : UIViewController
  159. - (IBAction)login;
  160. @property(weak,nonatomic)IBOutletUITextField *qqField;
  161. @property(weak,nonatomic)IBOutletUITextField *pwdField;

  162. @end
  163. // MJLoginViewController.m

    Map
  164. //
  165. //  MJLoginViewController.m
  166. //  02-导航实例-storyboard实现
  167. //
  168. //  Created by apple on 13-12-10.
  169. //  Copyright (c) 2013itcast. All rights reserved.
  170. //

  171. #import"MJLoginViewController.h"

  172. @interfaceMJLoginViewController ()

  173. @end

  174. @implementationMJLoginViewController

  175. - (void)viewDidLoad
  176. {
  177.     [superviewDidLoad];
  178. // Do any additional setup after loading the view.
  179. }

  180. - (IBAction)login {
  181.    if(_qqField.text.length ==0|| _pwdField.text.length ==0)return;
  182.    
  183.    
  184.    //手动执行那根线(一根线代表一个segue对象)
  185.     [selfperformSegueWithIdentifier:@"login2home"sender:@"789"];
  186. }

  187. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
  188. {
  189.     NSLog(@"----------------%@", sender);
  190. }
  191. @end

https://www.evernote.com/shard/s227/sh/5fea7b10-adcf-4efe-b616-493de3f9dde3/fdc9ac0c31864734d2ac3d7854795349

posted @ 2013-12-25 16:14  iTeaTime(技术清谈)  阅读(232)  评论(0编辑  收藏  举报