#import "ViewController.h"
#import "SecondViewController.h"
@interface ViewController ()
@property (retain, nonatomic) IBOutlet UITextField *textField;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (IBAction)pushButtonAction:(id)sender {
//跳转第一种方式
// SecondViewController *secondVC = [[SecondViewController alloc] init];
// [self.navigationController pushViewController:secondVC animated:YES];
//1.当要获取的视图控制器对象和当前视图控制器在同一个storyboard文件中
//从 storyboard 获取对应的视图控制器对象
//self.storyboard 获取当前视图控制器所在的 storyboard对象
/*
SecondViewController *secondVC = [self.storyboard instantiateViewControllerWithIdentifier:@"second"];
[self.navigationController pushViewController:secondVC animated:YES];
//2.当要获取的视图控制器对象和当前视图控制器在同一个storyboard文件中
//1.先创建storyboard对象
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Leo" bundle:nil];
//假设,另外一个storyboard的名字是Leo.stroyboard
//(2)从对应的storyboard中根据标识符,获取视图控制器对象
SecondViewController *second = [storyboard instantiateViewControllerWithIdentifier:@"reuse"];
//然后再push 即可
*/
//跳转第二种,根据桥跳转
//[self performSegueWithIdentifier:@"reuse" sender:nil];
//跳转第三种方式
//直接将按钮与下一个界面建桥即可,不用写任何代码,但是该方法只有一个弊端,因为这种方法为单个按钮单独定制的跳转,如果一个界面中有多个按钮都要跳转到这一个界面,还需要增加多个桥,这样的话,关系非常的冗杂,不如直接通过第二种方式(视图控制器与视图控制器之间建桥,让多个button点击方法实现跳转即可)
}
//通过桥(segue)完成页面的跳转,在跳转之前该方法就会出触发,一般用于传值.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
//获取下个界面的对象
SecondViewController *secondVC = segue.destinationViewController;
//传值
secondVC.data = self.textField.text;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)dealloc {
[_textField release];
[super dealloc];
}
@end
SecondViewController.h
#import <UIKit/UIKit.h>
@interface SecondViewController : UIViewController
@property (nonatomic, copy) NSString *data;
@end
SecondViewController.m
#import "SecondViewController.h"
@interface SecondViewController ()
@property (retain, nonatomic) IBOutlet UILabel *aLable;
@end
@implementation SecondViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.aLable.text = self.data;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)dealloc {
[_aLable release];
self.data = nil;
[super dealloc];
}
@end