UINavigationController+storyboard

新建ios工程,然后打开Main.storyboard,点击Editor--Embed in--Navigation Controller

UINavigationController+storyboard_第1张图片


2、指定storyboard中ViewController 对应ViewController ,并为其添加按钮,以及点击事件

UINavigationController+storyboard_第2张图片


为按钮添加点击事件后的ViewController实现类

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}
- (IBAction)nextClick:(id)sender {
    
    // 点击按钮后开启新的UIViewController,新的UIViewController根据storyboard2这个标志来获取
    UIViewController* nextVc=[self.storyboard instantiateViewControllerWithIdentifier:@"storyboard2"];
    [self.navigationController pushViewController:nextVc animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

3、新建ViewController2文件,并在storyboard中添加新的ViewController,然后指定id为storyboard2,关联ViewController2,并添加按钮点击事件

UINavigationController+storyboard_第3张图片


ViewCOntroller2实现类

#import "ViewController2.h"

@interface ViewController2 ()

@end

@implementation ViewController2

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}
- (IBAction)backClick:(id)sender {
    //返回上一级
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end

运行效果

          UINavigationController+storyboard_第4张图片

你可能感兴趣的:(ios)